我正在使用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响应是:
“NetworkError:400错误请求 - 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;%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)[0];%2 0%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(画布);%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((动作)(()%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(动态%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%20×%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"
答案 0 :(得分:2)
您正在使用JSONP。 JSONP仅支持GET请求。
配置服务器以返回普通JSON(具有相应的内容类型和访问控制标头)并省略dataType
参数(或将其设置为'json'
)。