我使用JSON进行跨域,我的代码是
var sourceCode = window.cseditor.getValue() || document.getElementById("sourcecode").value;
alert(sourceCode);
setStatus("Compiling...");
$.ajax({
type: "POST",
url: "http://jsil.org/try/compile.aspx",
contentType: "text/plain; charset=UTF-8",
cache:false,
dataType: "jsonp",
data: sourceCode,
success: compileComplete,
error: function (xhr, status, moreStatus) {
compileComplete(false, status + ": " + moreStatus);
},
});上面的ajax响应代码是:
“http://jsil.org/try/compile.aspx?callback=jQuery172012547365785923736_1415796582452&%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20using%20System;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20using%20JSIL;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20using%20JSIL.Meta;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20public%20static%20class%20Program%20{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20public%20static%20int%20x%20=%2010;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20public%20static%20int%20y%20=%2020;:400错误请求-NetworkError%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20public%20static%20void%20Main%20()%20{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dynamic%20document%20=%20Builtins.Global%22document%22;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dynamic%20window%20=%20Builtins.Global%22window%22;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20canvas%20=%20document.createElement(%22canvas%22);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20ctx%20=%20canvas.getContext(%222d%22);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20body%20=%20document.getElementsByTagName(%22body%22);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Console.WriteLine(%22Hello%20JSIL%20World!%22);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20body.appendChild(canvas);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20window.setInterval((Action)(()%20=%3E%20{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Redraw(ctx);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20}),%2025);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20public%20static%20void%20Redraw%20(dynamic%20ctx)%20{%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x%20+=%202;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ctx.clearRect(0,%200,%20300,%20300);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ctx.fillStyle%20=%20%22red%22;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ctx.fillRect(x,%20y,%2020,%2020);%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20&_=1415796586503“
发布于 2014-11-12 21:02:01
您正在使用JSONP。JSONP仅支持GET请求。
配置服务器以返回普通的JSON (带有适当的content-type和访问控制头),并省略dataType参数(或将其设置为'json')。
https://stackoverflow.com/questions/26887638
复制相似问题