我使用邮递员来测试我的网络服务。在http响应正文中,我找到了WS的响应。
当我在我的网络应用程序中使用ajax测试我的呼叫时,我再也找不到响应了。该选项卡包含一条消息“此请求没有可用的响应数据。”
这是我的ajax调用:
$.ajax({
url: url,
method: "POST",
data: params,
success:function(response) {
console.log(response); // no console here!
console.log('response');
},
error:function(){
console.log("error");
}
});
嗨,尝试这样。
在ajax中,您正在传递参数,它应该包含类似action = get_pincodes的内容。 在处理这个问题时,action = get_pincodes。 你必须写 echo json_encode($responce);exit;
EX:
if($_REQUEST['action'] != "" && $_REQUEST['action'] == 'get_pincodes'){
$responce = array();
$responce[] = "500113";
$responce[] = "500114"; // etc....
echo json_encode($responce);exit;
}
也许将 charset=utf-8 添加到响应标头中的 Content-Type 可以解决该问题:Content-Type: application/json;字符集=utf-8
$.ajax({
url: url,
method: "POST",
dataType: "json",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json;charset=utf-8'
},
data: params,
success:function(response) {
console.log(response); // no console here!
console.log('response');
},
error:function(){
console.log("error");
}
});