2016-09-09 35 views
1

我打电话阿贾克斯像下面如何在JQuery Ajax调用期间获取数据值?

$.ajax({ 
     type: "POST", 
     contentType: "application/json; charset=utf-8", 

     url: path, 
     dataType: "json", 

     data: '{ "jsondata":' + jsondata + ',"key":"' + getValue('id') + '"}', 
     success: function (data) { 
      callback(data); 
     }, 
     error: function (error) { 
      callback(error.responseText); 

     } 
    }); 

我想在打电话的时间才能拿到“数据”的值,因为调用后执行不转到所需的Web方法和错误显示像 ""Message":"Invalid web service call, missing value for parameter: \u0027obj\u0027..." 我必须在Ajax调用期间跟踪Ajax发布值,并找出发布数据的问题。是否有任何技巧在Ajax调用之前获取数据值? 任何帮助将不胜感激。

编辑:我发送jsondata值类似下面

var jsondata = '{ "pagenumber":"' + pagenumber + '","sortColumn":"' + sortColumn + '","sortDirection":"' + sortDirection + '","rowPerPage":"' + rowPerPage + '"}'; 

感谢。

+0

你需要检查你的'的getValue( '身份证')'应该'的getValue(ID)' – Webruster

+0

你有没有尝试过与之前发送的事件? – Chetan

+0

我一定误解了这个问题,因为对我的回答看起来像'var data ='{...}';的console.log(数据); $ .ajax({... data:data,...});'。你能解释一下你需要多一点的行为吗? – Andrei

回答

2

我只是用下面的代码检查 - 请看看。请beforesend内容

$.ajax({ 
    type: "POST", 
    contentType: "application/json; charset=utf-8", 

    url: '/dummy', 
    dataType: "json", 

    data: '{dummy:"dummy"}', 
    success: function (data) { 
     alert(data); 
    }, 
    error: function (error) { 
     alert(error); 

    }, 
     beforeSend: function(data,data1) { 

    console.log('before'+data1.data) 
}, 
}); 
}) 
}); 
+0

随时编辑 – Chetan

+0

数据值发送类似{“jsondata”:{“pagenumber”:“0”,“sortColumn”:“Name”,“sortDirection”:“asc”,“rowPerPage”:“10”} ,“key”:“PPCrAV0oUGhy1cRdNEiN/ohdzAwD3 + Qyyn5ozvhZ1B6STo0KrY +/Vggfnc4v12JS” } –

0
var path = "test_ajax.php"; 
    var jsondata = "Testing123"; 
    var test = "test"; 

    var data = {jsondata : jsondata,key : test}; 


    $.ajax({ 
    type: "POST", 
    contentType: "application/json; charset=utf-8", 

    url: path, 
    dataType: "json", 

    data: data, 
    success: function (data) { 
     alert("success:"+data); 
    }, 
    error: function (error) { 
     alert("failure"+error.responseText); 

    } 
});