2015-06-22 198 views
2

我已经通过所有建议的链接找出解决方案,但仍然当我试图让$.post()它发送GET作为Request_Method,它是给我的错误

GET https://example.com/samewebservice/save 405 (Method Not Allowed)

它是一个跨源请求,所以我已经启用所有CORS在服务器上, 设置如果我执行$.get()方法它给我以JSON格式响应成功。

但是,当m试图执行$.post()方法它给我错误。

POST Ajax请求

function postAjax(URL,jsonData){ 

    $.post(URL,jsonData,function(data){ 
    response = data; 
    alert("In success"); 
    console.log(data); 
    },"jsonp"); 
    return response; 
} 

在浏览器标题我得到这个

enter image description here

回答

4

只是一个猜测。尝试添加

function postAjax(URL,jsonData){ 
    $.post(URL,jsonData, 
    type:'POST', 
    function(data){ 
     response = data; 
     alert("In success"); 
     console.log(data); 
    }, 
    "jsonp"); 

    return response; 
} 

B/W上的JSONP数据类型可能会在这里的原因。检查这个answer

+0

不工作,'$ .post()'不接受'类型:'POST''作为参数 – rachana

+0

然后,您可以更改数据类型到'json'而不是'jsonp'或将'post'函数更改为'ajax' – Karthik

+0

我已经尝试过两种方法,但仍然不能正常工作 – rachana

0

你不能使用JSONP POST ...它创建一个<script>元素来获取数据......它必须是一个GET请求。

0

我有一个[FromBody]在我的“HttpRequestMessage请求”参数之前;这是不正确解析..........