我有一個如下所示的c#asmx web服務代碼。從Response.Write調用c#asmx web服務使用Response.Write JSON輸出
[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服務。這個web服務已經成功地在我的android項目中使用了。
當我嘗試使用通過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);
}
可能是什麼問題呢?
好的。讓我嘗試一個字符串並回復你。 –
修改代碼:var custid =「106206」; data:'{CustId:''+ custid +'「,PolicyType:」'+ policyType +'「}'。 –
它仍然是500內部服務器錯誤。 –