Call the PAGE method andWebService
Note:
In web. config, you must specify that the Web service can be called.
It must be called in post mode.
The Web service returns an XML string, so the client needs to convert it to JSON for further processing.
[Webmethod]
Public static StringAjaxservicetest (StringStr)
{
Return String. Format ("Hello, {0 }", STR );
}
[System. Web. Script. Services.Scriptservice]
Public Class Testwebservice: System. Web. Services.WebService
{
[Webmethod]
Public StringHelloworld (StringS)
{
Return "Hello World"+ S;
}
}
FunctionWebservicemethod (){
$. Ajax ({
Type:"Post",
Contenttype:"Application/JSON; UTF-8",
URL:"Testwebservice. asmx/helloworld",
Data:"{S :"""+ $ ("# Inputname"). Val () +"""}",// Pass the WebService method parameters. S is the method parameter and must be consistent.
Success:Function(Data ){
// Convert the returned string to a JSON object
VaRJSON =Null;
Try{
JSON = eval ('('+ Data +')');
}Catch(E ){
Alert ("The returned string is not in JSON format! ");
Return;
}
Alert (JSON. D );
}
});
}
FunctionPageajaxservicetest (){
$. Ajax ({
Type:"Post",
Contenttype:"Application/JSON; UTF-8",
URL:"Pageservice. aspx/ajaxservicetest",
Data:"{STR :"""+ $ ("# Inputname"). Val () +"""}",// Parameters passed to. CS static method. STR is a method parameter and must be consistent
Success:Function(Data ){
// Convert the returned string to a JSON object
VaRJSON =Null;
Try{
JSON = eval ('('+ Data +')');
}Catch(E ){
Alert ("The returned string is not in JSON format! ");
Return;
}
Alert (JSON. D );
}
});
}
</Script>
<Div>
<Input ID= "Inputname" Type= "Text" Value= "" />
A href =" # " onclick =" webservicemethod (); "> call Web service A > Br /> Br />
A href =" # " onclick =" pageajaxservicetest (); "> call Static Page methods A > Br /> Br />
</Div>
Note:
$. Post ("Pagingservice. asmx/getloginhtml", {S:"FDA"},
Function(Data ){
$ ("# Ajaxlogin"Pai.html (data );
Alert (data );
},"Html");