通过AJAX发送POST请求时,Chrome和Firefox错误

时间:2019-03-11 07:56:47

标签: javascript ajax google-chrome config access-control

我在QlikView Extension Application上通过POST触发了ajax调用,但遇到了net :: ERR_CONNECTION_REFUSED错误,但仅限于Chrome和Firefox。在Internet Explorer上,一切正常。我是否需要从Web服务中的配置文件发送任何登录数据,我该怎么做。

多数民众赞成在我的Ajax调用代码:

 $.ajax({
                url: "http://localhost:1052/SaveComment",
                contentType: "application/json; charset=utf-8",
                type: "POST",
                data: JSON.stringify(dataset),
                success: function (response) {
                    if (response == true) {
                        swal("Saved Succesfully!", "Your database have been updated succesfully.", "success");
                    } else {
                        swal("Failed!", "There was a problem with your entry, please try again.", "error");
                    }
                },
                error: function (xhr) {

                    // This is the message if the POST has failed and the WebService didnt receive the Data
                    swal("Server Error!", "There is an issue with the WebService, please contact Server Admin.", "error");
                }
            });
            $(this).find("input[type=text], textarea").val("");
        })
    }

那是我在web.config文件中的代码:

<customHeaders>
    <add name="Access-Control-Allow-Origin" value="http://127.0.0.1/QvAJAXZfc/opendoc.htm?document=qvApplication.qvw&lang=en-US&host=QVS%Server" />
    <add name="Access-Control-Allow-Headers" value="Content-Type" />
    <add name="Access-Control-Allow-Methods" value="GET,POST,PUT,DELETE,OPTIONS" />
    <add name="Access-Control-Allow-Credentials" value="true" />
 </customHeaders>

0 个答案:

没有答案