rextester restful api json错误

时间:2014-08-28 00:35:28

标签: 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 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 ) );
      }
  });

但如果我将dataType更改为 jsonp ,则错误将退回到

Uncaught SyntaxError: Unexpected token : rextester.com/rundotnet/api?callback=jQuery110202748815272934735_1409212747…%22Hello,%20Worlds!\%22);%20}%20}%22,%22Input%22:%22%22}&_=1409212747488:1

如果我点击将从控制台显示我期望以json格式返回的值:{"Warnings":null,"Errors":"Method \u0027main\u0027 must be in a class \u0027Rextester\u0027.","Result":"","Stats":"Compilation time: 0.84 sec, absolute service time: 0.85 sec","Files":null}

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

0 个答案:

没有答案