Ajax.Request 调用 WebService问题!极为困惑!
蝈蝈太阳 2008-04-15 01:57:33 the code as the following:
------------------------------------------------------------------------------------------
var url = 'http://localhost/Test3/WebService.asmx/HelloWorld';
var params = {mothod: 'post',
contentType: 'application/json',
encoding: 'utf-8',
/*postBody: {haha:'\''+$F(this.input)+'\''},*/
parameters: {haha:$F(this.input)},/**/
onSuccess: this.onajaxSuccess.bind(this),
onFailure: this.onajaxFailure.bind(this),
onException: function (e) {
otherValues+='exception<br>'+e.url+'<br>'+inspect(e)
+'<br>'+e.getHeader()+'<br>'+e.getStatus()+'<br>';
otherValues+=inspect(e.transport)+'<br>';
blackboard.update(otherValues);
},
onComplete: function (transport) {otherValues
+='completed<br>'+inspect(transport); blackboard.update(otherValues);}
};
this.request = new Ajax.Request(url, params);
-------------------------------------------------------------------------------------------
The web service is defined as the following:
-------------------------------------------------------------------------------------------
using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld(string haha)
{
string temp = "[{'key':'1', 'value':';lakjshf 787agf8 ..1671
111'},{'key':'2', 'value':'[lakjshf 787agf8 ..1671 111'},{'key':'3',
'value':'[lakjshf 787agf8 ..1671 333'}]";
return temp;
}
}
---------------------------------------------------------------------------------------------
if no parameters are transfered to the method, it is ok.
once passing some parameters in, the following error shows:
------------------------------------------------------------------------------------------------------------------------
System.InvalidOperationException: Request format is invalid:
application/json; charset=utf-8.
System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
============================================================