4

我使用邮递员来测试我的网络服务。在 http 响应正文中,我找到了 WS 的响应。

当我在我的 Web 应用程序中使用 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");
        }

    });
4

3 回答 3

0

你好,试试这样。

在 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;   
}
于 2019-09-05T09:16:54.133 回答
0

也许在响应标头中将 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");
    }

});

于 2019-09-05T09:31:49.903 回答
-2

尝试检查是否选择了 XHR 过滤器,然后不要忘记重新加载页面在此处输入图像描述

于 2019-09-05T09:06:17.347 回答