简体   繁体   English

jQuery Ajax请求仅在移动浏览器中失败

[英]JQuery Ajax request failing only in mobile browser

There are numerous posts where people ask this.. but it seems like the majority have issues when they use ajax requests for cross domain connection. 人们有很多帖子问这个..但是似乎大多数人使用ajax请求进行跨域连接时都遇到问题。 I simply use this on the same domain and still cannot manage to get the ajax request to work on my mobile browser... it works perfectly on the desktop browser though. 我只是在同一个域上使用它,但仍然无法设法使ajax请求在我的移动浏览器上工作……尽管它在桌面浏览器上可以完美运行。

This is the code I'm using: 这是我正在使用的代码:

Ajax Call 阿贾克斯电话

$.ajax({
    type: 'POST',
    url: '/test/Stores/storeCheck',
    data: $input,
    dataType: 'json',
    contentType: "application/x-www-form-urlencoded;charset=utf-8",
    success: function (data) {
      alert("success");
    },
    error:function (xhr) {
      alert("failed");
    }
});

PHP controller (cakephp) PHP控制器(cakephp)

function storeCheck () {

    if ($this->request->is('ajax')) {

        //Selecting values from the DB and returning them in $result

        $this->autoRender = false;
        return (json_encode($result));

    }

}

In my mobile browser the ajax request is made, and it just goes on until it reaches the error event showing me the failed alert popup. 在我的移动浏览器中,发出了ajax请求,并且一直持续到到达错误事件,向我显示失败的警报弹出窗口。 I've tried using JSONP as some suggested, but with no success. 我已尝试按照建议使用JSONP,但没有成功。 Any thoughts would be highly appreciated. 任何想法将不胜感激。

Br, A Br,A

I managed to resolve this issue. 我设法解决了这个问题。 I used echo instead of return in my controller function. 我在控制器函数中使用echo而不是return。 I also turned of the Debug for my ajax request in the controller: 我还针对控制器中的ajax请求打开了Debug:

function storeCheck () {

if ($this->request->is('ajax')) {

    Configure::write('debug', 0);

    //Selecting values from the DB and returning them in $result

    $this->autoRender = false;
    echo json_encode($result);

}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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