Use webform, websevice request operation performed ajax

By using webform (asp.net non-mvc), webservice interface to send a request in the foreground ajax request:
1. Reception Code:

1  $ .ajax ({
 2      of the type: "POST" ,
 3      // method and the method name where the page 
4      url: "../ztest.aspx/GetHtmlJson" ,
 5      // must be added, otherwise the default server returned is text / html; charset = utf- 8 format page 
. 6      contentType: "file application / json; charset = UTF-. 8" ,
 . 7      dataType: "json" ,
 . 8      // here we must pay attention: it must be a string json form 
. 9      Data: '{ID:' + $ ( "# htmlId") Val () +. '}' ,
 10      beforeSend: function () {
 . 11              index = layer.load (2 );
 12 is          },
13         Success: function (Data) {
 14              // data returned by the content acquisition data.d 
15              qjson = the JSON.parse (data.d);
 16              the console.log (qjson);
 . 17  
18 is          },
 . 19          error: function (ERR) {
 20 is              the console.log (ERR);
 21 is          }
 22 is });

 

Background 2.webform Code:
PS: when the returned data with the background base64 string deserialization json when long string may be error json errors, in this case required configuration file web.config Add the next node configuration:

1 <system.web.extensions>
2 <scripting>
3 <webServices>
4 <jsonSerialization maxJsonLength="1024000000" />
5 </webServices>
6 </scripting>
7 </system.web.extensions>

 

 

. 1 [the WebMethod] // add comments, using static method 
2  public  static  String GetHtmlJson ( int ID)
 . 3  {
 . 4  // ID = Convert.ToInt32 (); 
. 5  String htmlJson = String .Empty;
 . 6  IF (ID <= 0 )
 . 7  {
 . 8 htmlJson = "" ;
 . 9  }
 10  the else 
. 11  {
 12 is htmlJson = new new BLL.BLL_CommonWrongTopic () GetHtmlJson (ID);.
 13 is  }
 14  
15 return htmlJson;
16 }

 

Guess you like

Origin www.cnblogs.com/wangyuliang/p/10962743.html