Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自iFrame内部的jQuery POST请求超时_Jquery_Html_Ajax_Iframe_Bookmarklet - Fatal编程技术网

来自iFrame内部的jQuery POST请求超时

来自iFrame内部的jQuery POST请求超时,jquery,html,ajax,iframe,bookmarklet,Jquery,Html,Ajax,Iframe,Bookmarklet,我有一个iframe,它被bookmarklet注入到任意网页中。它指向http://localhost:5000/test,这是一个运行以下Javascript的简单HTML页面: $.ajax({ type: "POST", url: "http://localhost:5000/parse", data: {data:"hello world"} }).done(function( msg ) { console.log("Success!!", arguments); }

我有一个iframe,它被bookmarklet注入到任意网页中。它指向
http://localhost:5000/test
,这是一个运行以下Javascript的简单HTML页面:

$.ajax({
  type: "POST",
  url: "http://localhost:5000/parse",
  data: {data:"hello world"}
}).done(function( msg ) {
  console.log("Success!!", arguments);
}).fail(function(jqXHR, textStatus, errorThrown) {
  console.log("Error", arguments);
});
我可以在web inspector中看到调用已发出,但在30秒后请求超时之前,它一直处于(挂起)状态。服务器日志显示服务器根本没有被攻击。奇怪的是,如果我删除ajax请求中的数据参数,服务器就会受到攻击,事情就会按预期进行

$.ajax({
  type: "POST",
  url: "http://localhost:5000/parse"
}).done(function( msg ) {
  console.log("Success!!", arguments); // this works.
});

我不希望跨域策略问题成为问题,因为iframe和ajax请求目标位于同一个域上。我错过了什么?浏览器级别是否存在阻止此请求通过的内容?

尝试将数据类型和内容类型添加到ajax设置中

$.ajax({
   type: "POST",
   url: "http://localhost:5000/parse",
   contentType: 'application/json; charset=utf-8',
   dataType: 'json',
   data: {data:"hello world"}
 }).done(function( msg ) {
     console.log("Success!!", arguments);
 }).fail(function(jqXHR, textStatus, errorThrown) {
     console.log("Error", arguments);
 });

虽然对我来说添加这些可能是一个好主意(我现在有了),但它并没有解决问题。请求在超时之前仍处于挂起状态。您可能需要对数据进行字符串化,这里建议:使用JSON.stringify序列化对象不幸没有效果。