相关疑难解决方法(0)

jQuery .ajax()POST请求在RESTful WCF上抛出405(方法不允许)

我正在向RESTFUL WCF服务应用程序发送一个post请求.我能够POST通过Fiddler 成功发送请求.

但是,当我通过jQuery Ajax方法执行此操作时,该函数会将以下内容返回到Chrome Developer Console:

OPTIONS http://www.example.com/testservice/service1.svc/GetData 405 (Method Not Allowed) jquery.min.js:6
Run Code Online (Sandbox Code Playgroud)

但是之后的第二个日志:

Object {d: "You entered 10"} testpost.html:16
Run Code Online (Sandbox Code Playgroud)

这告诉我的是jQuery正在发送一个OPTIONS请求,该请求失败,然后发送一个POST返回预期数据的请求.

我的jQuery代码:

$.ajax() {        
type: "POST", //GET or POST or PUT or DELETE verb 
    url: "http://www.example.com/testservice/service1.svc/GetData", // Location of the service      
    data: '{"value":"10"}', //Data sent to server
    contentType:"application/json",
    dataType: "json", //Expected data format from server    
    processdata: false,
    success: function (msg) {//On Successfull service call   
        console.log(msg);
    },
    error: function (xhr) { console.log(xhr.responseText); } // …
Run Code Online (Sandbox Code Playgroud)

rest jquery post web-services wcf-rest

34
推荐指数
2
解决办法
14万
查看次数

标签 统计

jquery ×1

post ×1

rest ×1

wcf-rest ×1

web-services ×1