2009-09-02 10 views
0

にAJAX呼び出しと自動補完作業を行うことができない私は、この記事の指示に従っ:how can we integrate jquery autocomplete using asp.net, webservie and sql database私は私のWebサービス

がasp.netで私のWebサービスとのjquery-オートコンプリートのプラグインを動作させるためには、それだけではないだろう作業。

ローカルデータを使用するとオートコンプリートが機能します。私は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; 
     } 
    } 

EDIT:

これは私が内部サーバーエラーというタイトル取得応答があります。

<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&amp; completedSynchronously) +155 
</pre></code> 

        </td> 
       </tr> 
      </table> 

      <br> 

      <hr width=100% size=1 color=silver> 

      <b>Version Information:</b>&nbsp;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) 
--> 

EDIT:

だから私は、URLから/ HelloWorldの/一部を除去し、応答はもう エラーを生成しません。しかし、これは私の問題を解決しません。私は別の コールするメソッド名を渡す方法があると思いますか?

+0

私たちは、リクエストが行われたことを示すフィドラーまたはFirebugのスクリーンショットのように、ステータスコードとレスポンスの内容と一緒にさらに詳しい情報が必要です。 – redsquare

+0

エラーと共にレスポンスを追加しました。ありがとう。 – Riz

答えて

0

これで分かりました。

Find the function $.fn.extend({ 
under the function, find the line: url: isUrl ? urlOrData : null, 
under that line, insert the following line: type: isUrl ? null : urlOrData, 

Then find the function request(term, success, failure) { 
under it, find the line: port: "autocomplete" + input.name, 
under the line, add the following line: type: options.type, 

これはあなたが指定することができます:

この

では、次のようにjquery.autocomplete.jsファイルを変更する必要がありJörnZaefferer

ファーストで1.1プラグインjqueryのオートコンプリートですリクエストのタイプ。 Webサービスのwebメソッドを呼び出す場合は、オプションとして「POST」を指定します。今

私はとあなたがオートコンプリートの呼び出しを行う、次のように指定します。

type: "POST", 
dataType: "xml" 

これは、メソッドへのポストを行うにはjqueryのAJAXを伝えます。そして、それがうまくいく!

0

最初の例ではデータ型jsonを使用していますが、2番目の例ではオートコンプリートでxmlを使用しています。両方をjsonに変更しますか?

+0

私は2番目のものをjsonに変更しましたが、それと同じエラーです。 – Riz

関連する問題