简体   繁体   English

jQuery Ajax调用在WebKit浏览器中不起作用

[英]jQuery Ajax call not working in WebKit browsers

var postData = $('#postalCheckForm').serialize();
$.ajax({
    url: "check.php",
    type: "POST",
    dataType: "text",
    data: postData,          
    contentType: "application/x-www-form-urlencoded",
    success: function(responseData, textStatus, jqXHR) {
        if (responseData !== 'none') {
            window.location.href = '';
        } 

    },

    error: function(jqXHR, textStatus, errorThrown) {
        console.log(errorThrown);
    }
});

I have this JavaScript ajax call. 我有这个JavaScript ajax呼叫。 It sends the postal code to the php script and script is returning text value with response. 它将邮政编码发送到php脚本,并且脚本正在返回带有响应的文本值。

It is working in Firefox and in IE as expected. 可以正常在Firefox和IE中使用它。 But not working in webKit browsers (Chrome, Safari). 但不适用于webKit浏览器(Chrome,Safari)。 Instead of get response from php script page is reloaded and this string is added to URL: ?postal_input=TEST 而不是从php脚本页面获取响应,而是重新加载了此字符串并将其添加到URL:?postal_input = TEST

[SOLVED] return false to the end of js. [已解决]将false返回js末尾。

You have to add : 您必须添加:

 return false;

at the end of your code to avoid your form to be submited. 在代码末尾避免提交表单。

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

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