Aufruf WebMethod mit Parameter von jQuery-ajax fehl

Ich bin erstaunt über das folgende problem.

Ich eine " WebForm1.aspx' und ein 'WebService1.asmx'.
Wenn ich den Aufruf einer Webmethode in der WebService OHNE Parameter ('HelloWorld') funktioniert es einwandfrei. Wenn ich eine Methode aufrufen MIT Parametern ('SayHello') schlägt fehl.

Es nicht sogar auf die Methode (Haltepunkt habe ich gesetzt in der Methode nicht erreicht ist). Das xmlHttpRequest-Fehler 'Internal Server Error'

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
    [WebMethod]
    public string HelloWorld()
    {
        return "Hello World";
    }

    [WebMethod]
    public string SayHello(string firstName, string lastName)
    {
        return "Hello " + firstName + " " + lastName;
    }
}

meine WebForms1.aspx:

    <div><br />No Parameters </div>
<div id="NoParameters"></div>
<div><br />With Parameters</div>
<div id="WithParameters"></div>


<script type="text/javascript">
    $(document).ready(function () {
        //SayHello returns a string we want to display.  Examples A, B and C show how you get the data in native
        //format (xml wrapped) as well as in JSON format.  Also how to send the parameters in form-encoded format,
        //JSON format and also JSON objects.  To get JSON back you need to send the params in JSON format.

        //Test - call a function that returns a string.
        //No Parameters
        $.ajax({
            type: "POST",
            url: "WebService1.asmx/HelloWorld",
            data: "{}",
            dataType: "text",
            success: function (data) {
                $("#NoParameters").html(data); //show the string that was returned, this will be the data inside the xml wrapper
            }
        });

        //Example A - call a function that returns a string.
        //Params are sent as form-encoded, data that comes back is text
        $.ajax({
            type: "POST",
            url: "WebService1.asmx/SayHello",

            //data: "firstName=Aidy&lastName=F", //the data in form-encoded format, ie as it would appear on a querystring
            //contentType: "application/x-www-form-urlencoded; charset=UTF-8", //if you are using form encoding, this is default so you don't need to supply it

            data: "{firstName:'Aidy', lastName:'F'}", //the data in JSON format.  Note it is *not* a JSON object, is is a literal string in JSON format
            contentType: "application/json; charset=utf-8", //we are sending in JSON format so we need to specify this

            dataType: "text", //the data type we want back, so text.  The data will come wrapped in xml
            success: function (data) {
                $("#WithParameters").html(data); //show the string that was returned, this will be the data inside the xml wrapper
            }
            , error: function(xmlHttpRequest, status, err) {alert(err);}
        });
    });

Den code, den ich verwende, ist aus Beispielen aus dem internet. Ich habe versucht, die übergabe der Parameter als form codiert (conmmented out) und JSON. Nichts scheint zu funktionieren.

Was ist zu tun?

  • Könnte es sein, die version von jQuery 1.8.2?
  • Soll ich mich mit 'Fiddler'? (noch nicht benutzt, learning curve)
  • Würde die F12-tools in IE11 helfen?
  • Ist es IIS Express läuft lokal auf meinem dev PC?

Jegliche Hilfe würde sehr geschätzt werden.

Könnte es etwas falsch mit meinem browser? Es gibt eine Menge von 'A mit einer tilde oben es zeigt sich auf Seiten gegoogelt und ich hatte Probleme mit dem Absenden diese Frage von IE auf meinem Entwickler-Rechner. Auf meinem normalen PC die Vorlage war in Ordnung.Irgendeine Art von encoding-problem?

Ich habe versucht, das ganze Projekt auf einem anderen PC. Gleiche OS, gleiche VS2013 gleichen IE11 und es FUNKTIONIERT!.

InformationsquelleAutor Dick de Reus | 2014-04-15

Schreibe einen Kommentar