Home > Web Front-end > JS Tutorial > Examples of three methods of JavaScript calling the background_javascript skills

Examples of three methods of JavaScript calling the background_javascript skills

WBOY
Release: 2016-05-16 17:19:55
Original
1064 people have browsed it

Method 1: Directly use <%=%> to call

Front-end JS:

Copy code The code is as follows:


Back method:

Copy code The code is as follows:

public static string BehindMethod()
                                              >             return "This is a background method";

Method 2: Use ajax to call
Front-end js:

Copy code

The code is as follows:



Page html:





Copy code

The code is as follows:










Copy code

The code is as follows:[System.Web.Services.WebMethod] Public Static String Getimg (String Ext) { System.threading.thread.sleep (5000); // For the sake of waiting for 5 seconds
StringComparer SC = Ignorecase;
string[] extArr = new string[] { "php", "asp", "aspx", "txt", "bmp" }; , EXT); // Determine whether there is a

if (f)
{
Return "Image/54222860.jpg"; image/star1.jpg";
      }




Method 3: AjaxPro (also ajax)


Step one: Download AjaxPro.dll (or AjaxPro.2.dll) and add a reference to the project

Step 2: Modify the configuration file web.config

Copy code

The code is as follows:


Step 3: Register AjaxPro at runtime in the Page_Load event. Such as:





Copy code

The code is as follows:

protected void Page_Load(object sender, EventArgs e) { ajaxpro.utility.registerTypeForajax (Typeof (ajaxDemo)); // Register }
Step 4: Create the server method and mark it with [AjaxPro.AjaxMethod]





Copy code

The code is as follows:

[AjaxPro.AjaxMethod] public string GetImgByAjaxPro( :) Step 5: Calling front-end JS:
Copy code


The code is as follows:


function GetMethodByAjaxPro() {
var a = JustTest .AjaxDemo.GetImgByAjaxPro();//JustTest is the current namespace, AjaxDemo represents the background class             document.getElementById("imgAjaxPro").src = a.value; >
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template