L'appel de WebMethod avec des paramètres de jQuery ajax échoue

Je suis déconcerté par le problème suivant.

J'ai un " WebForm1.aspx' et un 'WebService1.asmx'.
Lorsque j'appelle un WebMethod dans le WebService SANS paramètres ('HelloWorld'), il fonctionne très bien. Quand j'ai appeler une Méthode AVEC des paramètres ('SayHello"), il échoue.

Il n'a même pas touché la méthode (point d'arrêt j'ai défini dans la méthode n'est pas atteint). Le xmlHttpRequest d'erreur est " Erreur Interne du Serveur

[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;
    }
}

mon 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);}
        });
    });

Le code que j'utilise est à venir à partir d'exemples à partir de l'internet. J'ai essayé de passer les paramètres à la fois comme forme codée (conmmented) et JSON. Rien ne semble fonctionner.

Que faire?

  • Pourrait-il être la version de jQuery 1.8.2?
  • Dois-je utiliser "Fiddler'? (n'ai pas encore utilisé, la courbe d'apprentissage)
  • Seraient les outils de développement F12 dans IE11 aider?
  • Est-il IIS Express qui s'exécute localement sur mon dev PC?

Toute aide serait grandement appréciée.

Pourrait-il y avoir quelque chose de mal avec mon navigateur? Il y a beaucoup de " A avec un tilde au-dessus affiche sur googlé pages et j'ai eu des problèmes de soumettre cette question à partir d'IE sur mon ordinateur du développeur. Sur mon PC normal, la présentation était très bien.Une sorte de problème d'encodage?

  • J'ai essayé de l'ensemble du projet sur un autre PC. Même OS, même VS2013 même IE11 et ça marche!!!.
InformationsquelleAutor Dick de Reus | 2014-04-15