无法获取输出。返回代码206.缺少值。

时间:2015-03-19 07:38:59

标签: javascript ajax

请帮忙。 我正在使用ajax对远程服务器进行同步调用。错误与异步调用相同。

function create_vswitch(endpoint,data){
        var response=send_recieve(endpoint,data);
        console.log(response.params.id);
        return response.params.id;
}
function configure_server_vswitch(endpoint,data){
        var response=send_recieve(endpoint,data);
        console.log(JSON.stringify(response));


function send_recieve(endpoint,data){
        var url=http://10.77.94.243/830a341f-5249-4704-bd49-a732063a7dcb + endpoint
        console.log(url);
        var response="";
        $.ajax({
             url: url,
             type: "POST",
             dataType:"json",
             data: data,
             contentType:"application/json",
             success:function(){console.log("success")},
             error:function(){console.log("ERROR")},
             async:false
             }).then(function(response){
                   resp=response;
            });
            return resp

$("#create").click(function() {
    var COMPUTE_VSWITCH_UUID=create_vswitch("/qvbn-switch-agent/compute.vswitch",{"name":"compute_vswitch_test102"});
    console.log(COMPUTE_VSWITCH_UUID);
    //var compute_server_uuid=
    configure_server_vswitch("/qvbn-switch-agent/compute.server",{"configuration":{"tid":"compute.vswitch","id":COMPUTE_VSWITCH_UUID}});
    });

我得到的控制台输出是:

http://10.77.94.243:8280/830a341f-5249-4704-bd49-a732063a7dcb/qvbn-switch-agent/compute.vswitch
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.
Done
739d4940-b12d-4a6c-8ba6-fad7d30ce78f
739d4940-b12d-4a6c-8ba6-fad7d30ce78f
http://10.77.94.243:8280/830a341f-5249-4704-bd49-a732063a7dcb/qvbn-switch-agent/compute.server
Done
{"code":206,"cid":"qvbb","reason":"missing values for attributes configuration","params":null,"result":false,"error":true}

正如你可以看到最后的o / t,它说的是“缺少属性配置的值”。我无法理解此代码的问题。有人可以告诉我这段代码有什么问题。

1 个答案:

答案 0 :(得分:1)

尝试将data: data,替换为data: JSON.stringify(data),