AJAX请求的ReadyState = 4和Status = 400

时间:2018-06-02 15:39:49

标签: javascript ajax

我正在创建一个使用JDoodle作为我的在线编译器的项目,就像Sphere Engine一样,它允许你编写代码并在你的服务器上编译它。

所以我有这个代码将你的程序(存储在var代码中)和其他细节发送到允许执行程序的url。



$(document).ready(function () {
// Submit form with id function.
    $("#submit").click(function () {
        var code = $("#code").val();

        $("#form_id").submit(); // Form submission.
        alert(code);

        var submission_ = {
            script       : code,
            language      : "java",
            versionIndex  : 0,
            clientId      : "akjsdkjaskdjasjdkasjdkajskdjaksj",
            clientSecret  : "aksdjkajsdkajsdkjaksdjkasjdkjasdkjaskdjaksjdkasjdkjsakdjkjaskdjk"
        };
        
        alert(JSON.stringify(submission_));

        $.ajax({
            type: "POST",
            url: "https://api.jdoodle.com/v1/execute",
            dataType: 'json',
            contentType: "application/json",
            data: submission_,
            success: function (msg) {
                alert("Data Saved: " + msg);
                // some suff there
            },
            error: function(msg) {
                var io = JSON.stringify(msg);
                alert(io);
            }
        })
    });
});




我收到了这样的错误:

{" readyState":4," responseText":" {\"错误\":\"无效的请求\& #34;,\" statusCode \":400}"," responseJSON":{"错误":"无效请求&#34 ;,"的StatusCode" 400}"状态" 400"状态文本":"错误"}

我该如何解决这个问题?提前谢谢。

0 个答案:

没有答案