提问人:Nimal 提问时间:2/7/2022 最后编辑:ADysonNimal 更新时间:2/16/2022 访问量:278
Chrome 中的 JQuery Ajax 发送 GET 而不是 POST,但在 Edge 中,它会正确发送
JQuery Ajax in Chrome sends GET instead of POST, but in Edge it sends correctly
问:
以下代码触发 GET 方法而不是 POST。
$.ajax({type: 'POST',url: 'http://localhost:8000/DoAsync',data: {i:e},dataType: 'script'
});
它发生在 Chrome 中。
但是,当我在 Edge 中使用相同的代码时,它会正确触发。
不知道如何在Chrome中解决它?我试图清除缓存。结果也一样。
答:
-1赞
Vlad
2/7/2022
#1
和 是 chrome 浏览器使用默认方法 GET 的明显标志。405 Method Not Allowed
Request Method: GET
您可以尝试而不是@aynber已经提到的,但只有在您使用旧的 jQuery 版本时才能解决问题。method: 'POST'
type: 'POST'
“type”是“method”的别名。如果您使用的是 jQuery 1.9.0 之前的版本。
评论
0赞
ADyson
2/7/2022
it would only solve the problem if you are using an old jQuery Version
...不,恰恰相反。“type” 和 “method” 从 1.9 开始都有效。但是如果 OP 使用的是 <1.9.0,那么从“类型”更改为“方法”会导致问题,而不是解决问题,因为在那些旧版本中它无法识别“方法”。所以这不是解决方案。
0赞
Nimal
2/16/2022
#2
当我用于访问服务器时,我在 Chrome 中收到了错误,但在 Edge 中没有收到错误。http://127.0.0.1:8000/
而要访问服务器,请在 Chrome 和 Edge 浏览器中正确执行该方法。http://localhost:8000/
POST
所以,现在我正在使用 .http://localhost:8000/
评论
method: 'POST'
type: 'POST'
"script": Evaluates the response as JavaScript and returns it as plain text. Disables caching by appending a query string parameter, _=[TIMESTAMP], to the URL unless the cache option is set to true. Note: This will turn POSTs into GETs for remote-domain requests. Prior to jQuery 3.5.0, unsuccessful HTTP responses with a script Content-Type were still executed.
api.jquery.com/jquery.ajaxhttp://127.0.0.1:8000/
http://localhost:8000/