簡體   English   中英

為什么不在jQuery的Ajax POST中獲取POST參數

[英]why not get POST parameters in ajax POST of jQuery

下面列出了代碼:

    $.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("數據更新失敗,請刷新回滾");
     }
    });

在服務器中,我無法獲取post參數,然后篡改ajax發送的請求,它根本不發送數據參數。 我不知道我在哪里錯。

先感謝您。

這樣的問題已在SO Jquery -ajax-post- send -options-as-request-method-in-firefox中被詢問和提出

這是因為在FF上具有相同的來源策略。 它僅允許您對自己的域執行XMLHTTPRequests。 也許您的腳本是從域“ localhost”加載的,而您的ajax請求已加載到“ localhost:3000”

嘗試這個

$.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("數據更新失敗,請刷新回滾");
     }
    });

將數據對象包裝在$ .param中即可。 它將將該對象轉換為字符串“ k = sdfa&v = dsfas”

嗨,請嘗試這樣的事情:

$.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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM