【发布时间】:2017-04-05 16:10:44
【问题描述】:
我有一个如下所示的 c# asmx Web 服务代码。
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void getPolicyDetails(string CustId, string PolicyType)
{
JavaScriptSerializer js = new JavaScriptSerializer();
Context.Response.Clear();
Context.Response.ContentType = "application/json";
clsPolicy data = new clsPolicy();
try
{
string policyTxt = "";
//get PolicyTxt from Database
data.Message = policyTxt.ToString();
}
catch (Exception ex)
{
}
Context.Response.Write(js.Serialize(data));
}
现在,我正在尝试在 asp.net 中使用此 Web 服务。这个网络服务已经在我的安卓项目中成功使用了。
当我尝试通过 javascript 调用它时,它给了我一个 500 - 内部服务器错误。下面是我的 Javascript 代码。
function getPolicy(policyType) {
$.ajax({
type: "POST",
url: "http://myurl/productsearch.asmx/getPolicyDetails",
data: '{CustId: 106206,PolicyType: "' + policyType + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
可能是什么问题?
【问题讨论】:
标签: javascript c# asp.net web-services