2011-02-02 24 views
6

faccioAjax chiamata pagina web metodo non funziona

<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script> 

<script type="text/javascript"> 
    function CallPageMethod(methodName, onSuccess, onFail) { 
     var args = ''; 
     var l = arguments.length; 
     if (l > 3) { 
      for (var i = 3; i < l - 1; i += 2) { 
       if (args.length != 0) args += ','; 
       args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"'; 
      } 
     } 
     var loc = window.location.href; 
     loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "Report.aspx" : loc; 
     $.ajax({ 
      type: "POST", 
      url: loc + "/" + methodName, 
      data: "{" + args + "}", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: onSuccess, 
      fail: onFail 
     }); 
    } 

    function success(response) { 
     alert(response.d); 
    } 

    function fail(response) { 
     alert("&#1054;&#1096;&#1080;&#1073;&#1082;&#1072;."); 
    } 

    function select() { 

     ........... 

     CallPageMethod("SelectBook", success, fail, ...........); 
    } 
</script> 

E il mio script manager è

<asp:ScriptManager ID="ScriptManager1" 
EnableScriptGlobalization="true" 
EnableScriptLocalization="true" 
EnablePageMethods="true" 
EnablePartialRendering="true" runat="server" /> 

Ma quando eseguo selezionare la funzione non ho niente ... nessun messaggio a tutti.

log di errore:

[ArgumentException]: Unknown web method SelectBook. 
Parameter name: methodName 
    at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName) 
    at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs) 
    at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

E il mio metodo Web:

<WebMethod()> Public Function SelectBook(ByVal values As String, ByVal valuesG As String, ByVal valuesX As String, ByVal valuesXG As String) As String 
    '.... 
    Return If(((vals.Length = valsG.Length) And (valsX.Length = valsXG.Length)), SQLModule.UpdateAdvCode(vals, valsG, valsX, valsXG), "Ошибка чтения диспетчерских кодов") 
End Function 

Se faccio solo alert (CallPageMethod ("SelectBook", il successo, non riescono, ........ ...)) Riesco a vedere "indefinito", ma cosa non definito ??? Ho provato a eseguire il debug di questo javascript ma non riesco a risolverlo. E 'stato lavorato e capisco come deve funzionare, ma non ho idea del motivo per cui è rotto per ora e su come risolverlo. Aiutatemi con questo per favore.

Qualche informazione in più

Server ASP.NET Development Server/10.0.0.0 
Date Thu, 03 Feb 2011 11:30:51 GMT 
X-AspNet-Version 4.0.30319 
Cache-Control private 
Content-Type text/html; charset=utf-8 
Content-Length 3517 
Connection Close 

perché vicino?

risposta

4

Problema risolto ....

<WebMethod()> Public SHARED Function SelectBook(ByVal values As String, ByVal valuesG As String, ByVal valuesX As String, ByVal valuesXG As String) As String 
    '.... 
    Return If(((vals.Length = valsG.Length) And (valsX.Length = valsXG.Length)), SQLModule.UpdateAdvCode(vals, valsG, valsX, valsXG), "Ошибка чтения диспетчерских кодов") 
End Function 

spendo 2 giorni per vedere che deve essere condivisa> _ <

0

ho lo stesso problema con $ .ajax, non so perché ma così ora sto usando $ .get() o $ .getJSON() per il mio XMLHTTPRequests. sembra ancora più veloce rispetto alla funzione $ .ajax().

+0

Lo stesso con $ .get() o $ .getJSON() :( – Cynede

+0

usa firebug e controlla se c'è qualche output simile a JSON ... – Axxxon

+0

post aggiornato con il log degli errori – Cynede

3

Sono state prese delle file di configurazione, è il modulo registrato

<httpModules> 
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
</httpModules> 
+0

non. Ho aggiunto, ma sembra che non ha aiutato – Cynede

+0

btw: non riesco a trovare tale modulo con riflettore. – Cynede

Problemi correlati