2011-11-07 55 views
8

Tengo este error cuando envío 2 parámetro de jQuery para WebMethod y el uso de múltiples params"mensaje": "no válido llamada de servicio web, valor que falta para el parámetro: u0027

{"Message":"Invalid web service call, missing value for parameter: \u0027haha\u0027.","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"} 

En jQuery:.

$(".txtNoiDung").focusout(function() { 
     $.ajax({ 
      type: "POST", 
      url: "QuanLyTin.aspx/test1cai", 
      data: JSON.stringify({ hahas: $(this).val(),tuans: "hahaha" }), 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function (msg) { 
       $("#vltxtNoiDung").text(msg.d) 
      }, 
      error: function (xhr, reason, ex) { 
       alert(reason); 
      } 
     }); 
    }); 

En código detrás

[WebMethod()] 
     public static string test1cai(string haha, string tuan) 
     { 
      return "Hi, "+haha + tuan; 
     } 

¿Cómo puedo resolverlo? Gracias chicos.

Respuesta

32

Su servicio está aceptando los parámetros con nombre y hahatuan, pero su JavaScript está pasando en hahas y tuans. Retire la "s" de ambos:

data: JSON.stringify({ haha: $(this).val(),tuan: "hahaha" }), 

Además, tenga en cuenta que estos parámetros mucho partido entre cliente-servidor y del lado del con mayúsculas y minúsculas.

4

Los nombres de las propiedades de los objetos de JavaScript deben coincidir con los nombres de los parámetros en el método del servicio web para que puedan vincularse adecuadamente. Actualmente tienes:

{ hahas: $(this).val(),tuans: "hahaha" } 

que probablemente debería ser:

{ haha: $(this).val(), tuan: "hahaha" } 
0

Usted debe estar pasando el mismo parámetro del método de la función en behinedto código, en su Ajax llamar

datos: "{ 'jaja': '" + 'sus datos' + 'Tuan':' "+ "sus datos" + "'}"

  • no debe haber ningún espacio como 'Tuan'
Cuestiones relacionadas