【发布时间】:2015-10-07 17:33:56
【问题描述】:
不知道为什么我得到这个但我得到这个错误:
Invalid web service call, missing value for parameter: \u0027sentQuery\u0027
尝试对我的 ASPX Web 服务执行 jQuery AJAX 时。
我的 AJAX 是这样的:
$.ajax({
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: 'json',
url: "http://localhost:7665/Service1.asmx/theQ",
data: "{\"sentQuery\":" + "\"SELECT OPRID FROM vwPS_BC_JOB_PERS_DAT\"" + "}",
success: function (data) {
console.log(data);
},
error: function (a) {
alert('ERROR: ' + a.responseText);
}
});
还有我的 VB 网络服务代码:
<WebMethod(CacheDuration:=60)> _
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json, XmlSerializeString:=False)> _
Public Sub theQ(ByVal sentQuery As String)
Dim results As Object = fetchSQLQ("query", sentQuery)
Try
Dim ser As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim strResponse As String = ser.Serialize(results)
Context.Response.Clear()
Context.Response.ContentType = "application/json"
Context.Response.AddHeader("content-length", strResponse.Length.ToString())
Context.Response.Write(strResponse)
HttpContext.Current.ApplicationInstance.CompleteRequest()
Catch ex As Exception
Context.Response.Clear()
Context.Response.ContentType = "application/json"
Context.Response.AddHeader("content-length", ex.Message.Length.ToString())
Context.Response.Write(String.Format("[ERROR: {0}]", ex.Message))
HttpContext.Current.ApplicationInstance.CompleteRequest()
End Try
End Sub
更新
我猜以下是正确的:
data: { sentQuery: "SELECT OPRID FROM vwPS_BC_JOB_PERS_DAT" },
但是,它确实会产生另一个错误:
Invalid JSON primitive: SELECT.
嗯????
【问题讨论】:
-
永远不要手动创建 json,这很容易出错,而且你已经犯了错误
-
我认为asp.net不会自动解析url中的json字符串,你为什么不使用普通的?key=value查询字符串
标签: jquery asp.net ajax vb.net web-services