【发布时间】:2022-02-16 21:16:17
【问题描述】:
以下代码触发 GET 方法而不是 POST。
$.ajax({type: 'POST',url: 'http://localhost:8000/DoAsync',data: {i:e},dataType: 'script'
});
这发生在 Chrome 中。
但是,当我在 Edge 中使用相同的代码时,它会正确触发。
不知道如何在 Chrome 中解决?我试图清除缓存。同样的结果。
【问题讨论】:
-
试试
method: 'POST'而不是type: 'POST' -
第一张截图中的querystring参数对逻辑有什么影响?控制台中是否有任何错误?这个 AJAX 请求是在提交表单并且没有阻止该表单提交时发出的吗?我的观点是,发生这种情况有几个原因,但是如果没有看到更完整的代码示例,我们无法有效地帮助您。任何这样做的尝试都是猜测。
-
我们需要该问题的minimal reproducible example。 jQuery $.ajax 本身不会这样做,或者至少在不同的浏览器中没有不同,AFAIK。我想知道是否还有其他一些 JS 问题可能导致直接提交表单而不是一些 JS 触发,或类似的东西。虽然现在很难看出 Chrome 会出什么问题,但 Edge 却没有,但它们非常兼容。
-
"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.ajax -
问题在于通过
http://127.0.0.1:8000/或http://localhost:8000/处理请求。我已经发布了一个单独的答案。
标签: jquery ajax google-chrome