HTTP 500错误jQuery的Ajax和Web服务 [英] HTTP 500 Error jQuery Ajax with Web service
问题描述
我在一个单一的Visual Studio解决方案两个简单的项目,要了解一个jQuery Ajax请求的工作原理。一个是一个web服务和第二个是耗时的web服务的项目。
您可以从这里下载的非常小的项目。 下载项目文件
正如你可以在项目中看到,每当我尝试调用Web服务,内部服务器错误500发生。
在Chrome浏览器,我可以看到下面的警告
(由Ajax调用的错误功能执行)
请帮助我找到问题所在。
编辑:
函数btnClick(){
调试器;
VAR txtValue = $('#txtValue');
VAR文本= txtValue.val();
//
//
$阿贾克斯({
网址:HTTP://本地主机:12000 / ExampleJsonWS.asmx /的getValue
键入:POST,
数据类型:JSON,
数据:{+ txtValue.val()+},
超时:30000,
异步:假的,
的contentType:应用/ JSON的;字符集= UTF-8,
成功:功能(数据){
调试器;
警报(数据);
返回的数据;
},
错误:函数(结果){
调试器;
//警报(E);
警报(result.status +''+ result.statusText);
}
});
}
但问题是,它不可以张贴在保持Web服务在不同的项目,而一个GET可以做到这一点。 (由菲利普·海登的解释)。如果我没有理解错了或者有人想分享更多关于它,那么欢迎他们:)
有关更多信息,你可以看看这个 链接
更好的选择是保持一个Web服务的项目中,并调用其他web服务(这是必要的)到项目的Web服务。
I have two simple projects in a single Visual Studio solution to understand how a jQuery ajax request works. One is a web service and the second one is a project consuming the web service.
You can download the very small project from here. Download Project file
As you can see in the project, Whenever I try to call the Web Service, Internal Server Error 500 is occurring.
In chrome, I can see the following alert (executed by "Error" function of Ajax call)
Please assist me to find the problem..
EDIT:
function btnClick() {
debugger;
var txtValue = $('#txtValue');
var text = txtValue.val();
//
//
$.ajax({
url: "http://localhost:12000/ExampleJsonWS.asmx/getValue",
type: "POST",
dataType: "json",
data: "{" + txtValue.val() + "}",
timeout: 30000,
async: false,
contentType: "application/json; charset=utf-8",
success: function (data) {
debugger;
alert(data);
return data;
},
error: function (result) {
debugger;
//alert(e);
alert(result.status + ' ' + result.statusText);
}
});
}
The problem was that its not possible to POST with keeping the web service in different project while a GET can do that. (Explained by Phillip Hayden). If I understand it wrong or someone want to share more about it, then they are welcome :)
For more info you can have a look at this link
The better alternative is to keep a Web service inside the project and call the other Webservice (which is needed) into the Project's web service.
这篇关于HTTP 500错误jQuery的Ajax和Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!