简体   繁体   中英

why not get POST parameters in ajax POST of jQuery

The code is listed below:

    $.ajax({
     type: "POST",
     url: "http://localhost:3000/rcm/global_config/update",    
     data: {k: 'sdfa', v: 'dsfas'},
     success: function(data, textStatus, XMLHttpRequest){
       alert("数据更新成功");
     },
     error: function(xhr,textStatus, errorThrown){
       alert("数据更新失败,请刷新回滚");
     }
    });

In the server i can not get post parameters, and then i tamper the request sent by ajax, it doesn't send the data params at all. i don't know where i am wrong.

thank you in advance.

This issue has been asked and aswered before in SO jquery-ajax-post-sending-options-as-request-method-in-firefox

This is because the same origin policy on FF. It only allows you to do XMLHTTPRequests to your own domain. Maybe your script is loaded from domain "localhost" and your ajax request to "localhost:3000"

Please try this

$.ajax({
 type: "POST",
 url: "http://localhost:3000/rcm/global_config/update",    
 data: "{'k': 'sdfa', 'v': 'dsfas'}",       // Change are here in this line
 success: function(data, textStatus, XMLHttpRequest){
   alert("数据更新成功");
 },
 error: function(xhr,textStatus, errorThrown){
   alert("数据更新失败,请刷新回滚");
 }
});
   $.ajax({
     type: "POST",
     url: "http://localhost:3000/rcm/global_config/update",    
     data: $.param({k: 'sdfa', v: 'dsfas'}),
     success: function(data, textStatus, XMLHttpRequest){
       alert("数据更新成功");
     },
     error: function(xhr,textStatus, errorThrown){
       alert("数据更新失败,请刷新回滚");
     }
    });

Wrapping the data object in $.param should do it. It will convert that object to the string "k=sdfa&v=dsfas"

hi please try somthing like this:

$.ajax({
        type:"POST",
        url:"student/info/ajax.php",  
        data:({type:'test', r:which}),
        success:function(data){
            if((data.result)=='true')
                $('#result_popup').html(data.output);
            }, 
        dataType:"json"});
        return false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM