我跟着這個職位的方向:how can we integrate jquery autocomplete using asp.net, webservie and sql database我不能讓與AJAX調用自動完成工作,我的web服務
,使jQuery的自動完成插件的工作與我的asp.net web服務,但它只是不會工作。
自動完成工作,如果我做本地數據。我也可以使用jquery ajax調用我的web服務。有人可以告訴我我做錯了什麼嗎?代碼:
//This jquery ajax call works perfectly
function AjaxTest() {
$.ajax({
type: "POST",
url: "/Services/OSServices.asmx/HelloWorld",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: RenderTest
});
}
//this autocomplete ajax call doesn't work. It doesn't even hit the breakpoint in the
web service
$("#lastName").autocomplete("/Services/OSServices.asmx/HelloWorld", {
parse: function(data) {
var parsed = [];
$(data).find("string").each(function() {
parsed[parsed.length] = {
data: [$(this).text()],
value: $(this).text(),
result: [$(this).text()]
};
});
return parsed;
},
datatype: "xml"
});
//this is the webservice code:
[WebService(Namespace = "http://tempuri.org")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class OSServices : System.Web.Services.WebService
{
[WebMethod]
public string[] HelloWorld()
{
string[] myArray = { "blah1", "blah2", "blah3" };
return myArray;
}
}
編輯:
這是我得到題爲內部服務器錯誤的響應。
<html>
<head>
<title>Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'.</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
<h2> <i>Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'.</i> </h2></span>
<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
<b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
<br><br>
<b> Exception Details: </b>System.InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'.<br><br>
<b>Source Error:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code>
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>
</td>
</tr>
</table>
<br>
<b>Stack Trace:</b> <br><br>
<table width=100% bgcolor="#ffffcc">
<tr>
<td>
<code><pre>
[InvalidOperationException: Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'.]
System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response) +405961
System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) +212
System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated) +47
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +193
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
</pre></code>
</td>
</tr>
</table>
<br>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
</font>
</body>
</html>
<!--
[InvalidOperationException]: Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'.
at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath)
at System.Web.Script.Services.ScriptHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String pathTranslated)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->
編輯:
所以我刪除了/的HelloWorld /部分來自URL,響應已不產生 錯誤。但是,這並不能解決我的問題。我想有另一種 的方式來傳遞方法名稱來調用?
好吧,我們需要更多的信息,如顯示正在發出的請求和任何響應以及狀態碼和響應內容的Fiddler或Firebug屏幕截圖。 – redsquare 2009-09-02 17:13:02
我已將響應與錯誤一起添加。謝謝。 – Riz 2009-09-02 17:44:43