我是网络服务新手,当我尝试在 Chrome 控制台中运行我的页面(本地)时,出现以下错误
错误
<小时/>Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
http://localhost:12015/myWebService.asmx?op=GetCategories
相关代码如下:
jQuery
$.ajax({
url: "http://localhost:12015/myWebService.asmx?op=GetCategories",
type: "POST",
------------
------------
success: function (data) {
var categories = data.d;
$.each(categories, function (index, category) {
category.CategoryId).text(category.CategoryName);
});
},
error: function (e) { //always executing 'error' only
alert("hello");
}
网络服务 URL
<小时/>
http://localhost:12015/myWebService.asmx
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Categories> GetCategories()
{
//code
}
页面网址
http://localhost:11761/Default.aspx
编辑:当我刚刚包含 dataType: 'jsonp'
时,错误消失了,但现在又出现了另一个错误。
Uncaught SyntaxError: Unexpected token <
:12015/myWebService.asmx?op=GetCategories&callback=jQuery183010907560377381742_1356599550427&{}&_=1356599550438:3
当我单击链接(错误中提到的)时,它正在显示该页面。那可能是什么问题呢?我不知道错误意味着什么(也不知道要显示代码的哪一部分)。请帮忙。
相关
最佳答案
试试这个
[WebMethod]
[ScriptMethod(UseHttpPost = true)]
public List<Categories> GetCategories()
{
//code
}
或编辑web.config
<system.web>
...
<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/> -->
<add name="HttpGet"/>
<add name="Documentation"/>
<add name="HttpPostLocalhost"/>
</protocols>
</webServices>
...
</system.web>
关于jquery - 服务器响应状态为 405(不允许方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14051432/