at present , I will asp.net There are several ways of interaction between interface and background code :

1、webform+ Server control interaction ;

2、webform+jquery+ajax+ General handler interaction ;

3、webform+jquery+ajax+Webservice/WCF Interaction ;

4、MVC;

5、webform+jquery+ajax Direct interaction ;

Among them the first 1 This kind of interaction is the entry level , The development level is the second 2 With the first 3, The interaction is similar to , It's also my common way of development . The first 4 The species have only appeared in recent years , Yes , Less for projects .

Now record the number one 5 Two ways of interaction .

First step : Prepare the page code ;

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title> </head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btn" runat="server" Text=" Validate users " />
<asp:Button ID="btn1" runat="server" Text=" Validate users 1" />
</div>
</form>
<script src="http://cdn.renzaijianghu.com/Static/Script/jquery-1.9.1.js"></script>
<script src="http://cdn.renzaijianghu.com/Static/Script/Json2.js"></script>
<script src="../Static/Script/Core.js"></script>
<script> $(function () {
// Call methods without parameters
$("#btn").click(function () {
var url = JHSoft.currentURL + "/GetStr";
$.ajax({
type: "post", // Use post The way
async: false,
url: url,// Method page and method name
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data.d);// The data is returned with data.d Get content
},
error: function (err) {
alert(err);
}
});
});
// Call methods with parameters
$("#btn1").click(function () {
var url = JHSoft.currentURL + "/GetData";
var data = new Object();
data["str"] = " I am a ";
data["str2"] = "XXX"; $.ajax({
type: "post", // Use post The way
url: url,// Method page and method name
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON2.stringify(data), //Json serialize
success: function (data) {
alert(data.d);// The data is returned with data.d Get content
},
error: function (err) {
alert(err);
}
});
});
});
</script>
</body>
</html>

The second step : Get ready .cs Background code ;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services; // Reference namespace namespace JHSoft.Ed2k.UILogic
{
public class TorrentDownload : System.Web.UI.Page
{
protected void PageLoad(object sender, EventArgs e)
{ } [WebMethod]
// Must be marked and declared static
public static string GetStr()
{ return "HelloWorld!";
} [WebMethod]
public static string GetData(string str, string str2)
{
return str + str2;
}
}
}

The third step :Core.js Code

var JHSoft = JHSoft || {};
// Current page 
JHSoft.currentURL = document.URL;

Jquery Ajax call aspx More articles on page examples

  1. Jquery Ajax call aspx Page method

    Jquery Ajax call aspx Page method stay asp.net webform In development , use jQuery ajax There are several ways to transfer values 1) Common play : Through the general process ashx To deal with : 2) Advanced play : adopt as ...

  2. jquery.ajax request aspx and ashx Similarities and differences Jquery Ajax call aspx Page method

    1.jquery.ajax request aspx request aspx We should pay attention to the problem of static method : (1)aspx The background method of must be static , And add webmethod characteristic (2) stay ajax In the method contentType Must be “a ...

  3. Jquery Ajax call aspx Page method ( Reprint )

    stay asp.net webform In development , use jQuery ajax There are several ways to transfer values 1) Common play : Through the general process ashx To deal with : 2) Advanced play : adopt aspx.cs Static methods in +WebMethod Into the ...

  4. Jquery ajax Call the background aspx Background file method ( No ashx)

    stay asp.net webForm In development , use Jquery ajax call aspx There are two common ways to create a page : Let me briefly introduce . (1) adopt aspx.cs Static method of +WebMethod To deal with A brief introduction ...

  5. jQuery ajax Call the background aspx Two common methods of background files ( No ashx)

    stay asp.net webForm In development , use Jquery ajax call aspx There are two common ways to create a page : Let me briefly introduce . [WebMethod] public static string SayHe ...

  6. WCF Introductory tutorial ( Four ) adopt Host Code to host services One WCF Use TCP An example of agreement for communication jquery ajax call WCF, use System.ServiceModel.WebHttpBinding System.ServiceModel.WSHttpBinding agreement Study WCF Note 2 No nonsense WCF Introductory course 1 [ What is? WCF]

    WCF Introductory tutorial ( Four ) adopt Host Code to host services Posted on 2014-05-15 13:03  The wind that stays   read (7681) Comment on (0)  edit   Collection WCF Introductory tutorial ( Four ) adopt Host Code way to ...

  7. JQuery ajax call asp.net Of webMethod

    This article reprints :http://www.cnblogs.com/zengxiangzhan/archive/2011/01/16/1936938.html stay vs2010 in , use JQuery ajax call as ...

  8. jquery ajax Call return json Format data processing

    Ajax Requests are asynchronous by default If you want to synchronize async Set to false Can ( The default is true) var html = $.ajax({ url: "some.php", async: ...

  9. jquery ajax call WCF, use System.ServiceModel.WebHttpBinding

    Jquery ajax call WCF service The effect of the example is as follows : Original interface Click button GetList get after , By the appointed Url Get the data and add it to table Create a new console project , add to IContract.cs,DBServi ...

Random recommendation

  1. Student Management system

    Use a three-tier architecture to achieve Student Management system , It is divided into Studrnt.Model layer ,Student.DAL layer ,Student.BLL Layer and the Student.UI layer Step analysis : 1. stay Student.Model add to S ...

  2. 【Leetcode】【Hard】Insert Interval

    Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessa ...

  3. Python Some built-in functions and os And so on

          len(obj)                   # Find the length :obj It can be str.list Objects such as    split(str, num)          # str- Separator , Default space : ...

  4. iOS Jump of controller 、 Jump in four directions of the page

    Jump in the specified sliding direction CATransition *transition = [CATransition animation]; transition.duration = 0.3f; transitio ...

  5. Volley Framework analysis ( Two )--RequestQueue Core interpretation

    centered RequestQueue Read it , Its two request queues CacheQueue.NetworkQueue How is it called , The first is the execution process of the request and how to deal with repeated requests ? Yes RequestQueue And related classes ...

  6. Hibernate The batch

    The batch Consider a situation , You need to use Hibernate Upload a lot of data to your database . Here are the USES Hibernate To achieve this code fragment : Session session = SessionFact ...

  7. DDD Domain model enterprise system ( 3、 ... and )

    Related codes : public static void ShowArray() { // data source int[] arrayas = new int[] { 1, 2, 3, 4 }; // Create a query var qu ...

  8. jQueryeasyUI+Hibernate+struts2 Realize the mall background management of the add operation unique verification

    1. stay admin.js Add extended validation operations to checkName var checkUrl = "./hytc/AdminAction_check.action";

  9. Computer science C Language programming learning focus : It's easy to make a pointer

    C Languages are process-oriented , and C++ It's object-oriented C and C++ The difference between : C It's a structured language , It focuses on Algorithms and data structures .C The primary consideration of program design is how to pass a process , For input ( Or environmental conditions ) Run the operation to get the output ( Or implementation ...

  10. this And JavaScrip Four call modes in

    this What is it? Method call pattern Constructor call pattern Function call mode apply/call Pattern this What is it? —In most languages, ‘this’ is a reference to the ...