JQuery - $.ajax POST does not send .data to web server

后端 未结 5 911
你的背包
你的背包 2021-01-17 18:31

I am using the JQuery $.ajax post command to invoke an ajax event on my web server:

var formParams = \"fe1=y&fe2=m&fe3=m\";

$.ajax({
    type: \'POS         


        
5条回答
  •  遇见更好的自我
    2021-01-17 18:43

    After frustratingly trying for four hours, I found out that it is able to achieve this by setting the contentType in ajax POST as follows,

    var dataToSend = {
         "username" : $("#username").val(),
         "password" : $("#password").val()
    };
    
    $.ajax({
       type: "POST",
       url: "somepage.jsp",
       data: dataToSend,  
       contentType: "application/x-www-form-urlencoded; charset=UTF-8", //this is must
       success: function(datum, msg, textStatus){
            $("#result").html("

    " + "Status : " + msg + "

    ") .fadeIn("slow"); } });

提交回复
热议问题