Ajax GET可以正常工作,但POST不起作用

时间:2011-09-08 10:16:45

标签: ajax jquery

我使用Ajax发出请求,当我使用GET时请求正常。如果我在我的脚本和我的Rest-Service中使用POST,则不会。

$.ajax({
    type: 'POST',
    url: 'http://localhost/WebRestService/rest/User/deletePC',
    dataType: "text",
    success: function(antwort){
        alert("response:"+antwort);
        if (window.DOMParser)
        {
            parser=new DOMParser();
            xmlDoc=parser.parseFromString(antwort,"text/xml");
        }
        else // Internet Explorer
        {
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(antwort);
        } 
    },
    error:function(x,e){
        if(x.status==0){
            alert('You are offline!!\n Please Check Your Network.');
        }else if(x.status==404){
            alert('Requested URL not found.');
        }else if(x.status==500){
            alert('Internel Server Error.');
        }else if(e=='parsererror'){
            alert('Error.\nParsing JSON Request failed.');
        }else if(e=='timeout'){
            alert('Request Time out.');
        }else {
            alert('Unknow Error.\n'+x.responseText);
        }
    }
});

如果我使用POST,我会收到未知错误。有什么问题?

THX!

编辑:DELETE和PUt也不起作用。 Edit2:如果我使用firefox Poster它可以正常工作。

1 个答案:

答案 0 :(得分:0)

我在你的ajax请求中发送的数据在哪里? 发送帖子请求时,您必须识别要发送的数据。 您缺少帖子请求的data属性。

$.ajax({

 type: 'POST',
    url: 'http://localhost/WebRestService/rest/User/deletePC',
    data:'some data',
   dataType: "text",
  success: function(antwort){
    alert("response:"+antwort);
    },
});

如需进一步阅读,请参阅here

相关问题