jQuery AJAX响应错误(FF和Safari无法正常工作)

时间:2012-08-02 21:28:19

标签: php ajax jquery

在Safari和Firefox中,代码的响应部分无效(即来自PHP - > Ajax - > jQuery)。这些变量肯定会使PHP很好(使用mail()测试),所以它可能代表我的一些小错误!

jQuery的:

$.ajax({
    type: "POST",
    dataType: "json",
    data: postData,
    url: "http://www.kudiclub.com/test/login/?loginsub",
    success: function(data){
        if(data.success==false){
            $("#login .error").html(data.reply).show();
            $("#login-email").val(data.email);
            $("#password").val("");
        }else{
            window.location = data.ref;
        }
    }
});

PHP:

$data = array('success' => false, 'reply' => 'Username and password did not match.', 'email' => $email);
print json_encode($data);
return;

希望有人可以提供帮助。谢谢,尼克。

经过多次调整后,事实证明它没有看到完整的URL作为相对路径。将url更改为'/test/login/?loginsub'就可以了。

1 个答案:

答案 0 :(得分:0)

服务器说:Content-Type:text / html。不是json文档(application / json)。

http://www.kudiclub.com/test/login/?loginsub

GET /test/login/?loginsub HTTP/1.1
Host: www.kudiclub.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20100101 Firefox/13.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Cookie: PHPSESSID=060b8210adfb3c67ff792b9471c7fa1c
Cache-Control: max-age=0

HTTP/1.1 200 OK
Date: Thu, 02 Aug 2012 22:12:10 GMT
Server: Apache
X-Powered-By: PHP/5.2.17
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=2, max=200
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html