Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.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
Javascript rextester restful api json错误_Javascript_Json_Api_Jsonp_Restful Url - Fatal编程技术网

Javascript rextester restful api json错误

Javascript rextester restful api json错误,javascript,json,api,jsonp,restful-url,Javascript,Json,Api,Jsonp,Restful Url,大家好。我试图在rextester restful API上发送一个post请求,该请求将返回一个json字符串,但它只会抛出一个错误: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://rextester.com/rundotnet/api. This can be fixed by moving the resource to the sam

大家好。我试图在rextester restful API上发送一个post请求,该请求将返回一个json字符串,但它只会抛出一个错误:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://rextester.com/rundotnet/api. This can be fixed by moving the resource to the same domain or enabling CORS.
使用我的代码:

    $.ajax({ // ajax call starts
      type: 'POST',
      url: 'http://rextester.com/rundotnet/api', 
      data: data,
      dataType: 'json',
      contentType: "application/json",
      accepts: "application/json",
      success: function(data) {
          console.log( "success" + JSON.stringify( data ) );
      }, error: function (data) {
          console.log( "error" + JSON.stringify( data ) );
      }, complete: function ( data ) {
          console.log( "complete" + JSON.stringify( data ) );
      }
  });
但是,如果我将数据类型更改为jsonp,错误将后退到

Uncaught语法错误:意外标记:rextester.com/rundotnet/api?callback=jquery10202748815272934735\u 1409212747…%22Hello,%20Worlds!\%22);%20} %20}%22,%22输入%22:%22%22}&=1409212747488:1

如果我单击它,将从控制台显示json格式的返回值:
{“Warnings”:null,“Errors”:“Method\u0027main\u0027必须在类\u0027Rextester\u0027中”,“Result”:“Stats”:“编译时间:0.84秒,绝对服务时间:0.85秒”,“Files”:null}

有什么建议吗?tnx
API仅支持POST请求,并将返回JSON字符串值

我已经在响应头中添加了
访问控制允许原点:
。您最初的方法现在应该可以工作了。另外,从服务器端发出这样的请求可能更好,因为可能不是所有浏览器都支持跨源请求。我已经将
添加到了我的php文件中,但仍然出现了错误否,我的意思是在您调用时添加了该头(我是rextester的维护者)。如果这不起作用,那么您应该从服务器端进行调用。