Ajax is not a new programming language, but a technology for creating better, faster, and more interactive web applications.
Use JavaScript to make requests to the server and handle the response without blocking the user! The core object XMLHTTPRequest. With this object, your JavaScript can exchange data with the web server without overloading the page, that is, you can produce a partial refresh without having to refresh the page.
Ajax uses asynchronous data transfer (HTTP request) between the browser and the web server, which allows the web page to request a small amount of information from the server instead of the entire page.
Ajax makes Internet applications smaller, faster, and more friendly.
Ajax is a browser technology that is independent of web server software. Ajax is based on the following web standards:
JavaScript, XML, HTML, and CSS Web standards used in Ajax are well defined and supported by all major browsers. Ajax applications are independent of browsers and platforms.
Web applications have many advantages over desktop applications; they can be used by a wide range of users, they are easier to install and maintain, and they are easier to develop.
However, Internet applications are not as sophisticated and friendly as traditional desktop applications. With Ajax, Internet applications can be made more sophisticated and friendly.
Ajax instance calling method1. Create a new demo.aspx page.
2. First add a reference to the background file demos.aspx.cs on this page.
Using System.Web.Services;
3. Method call without parameters.
Everyone noticed that this version can't be lower than the .net framework 2.0. 2.0 is not supported. Background code:
[WebMethod] public staTIc string SayHello() { return "Hello Ajax!"; }
JS code:
$(funcTIon() { $("#btnOK").click(funcTIon() { $.ajax({ //Post type: "Post", // method where the page and method name url: "Demo. Aspx/SayHello", contentType: "applicaTIon/json; charset=utf-8", dataType: "json", success: function(data) { //Returned data uses data.d to get the content alert(data.d); }, error: function(err) { alert(err); } }); //Disable button commit return false; }); });
Page code:
"form id="form1" runat="server"""div" "asp:Button ID="btnOK" runat="server" Text="verify user" /" /div" /form
The effect is as follows:
3. There are parameter methods to call the background code:
[WebMethod] public static string GetStr(string str, string str2) { return str + str2; }
JS code:
$(function() { $("#btnOK").click(function() { $.ajax({ type: "Post", url: "demo.aspx/GetStr", //method of the method argument must be written Yes, str is the name of the formal parameter, str2 is the name of the second formal parameter data: "{'str': 'I am', 'str2': 'XXX'}", contentType: "application/json; charset= Utf-8", dataType: "json", success: function(data) { //Returned data with data.d to get the content alert(data.d); }, error: function(err) { alert(err); } }); //Disable button commit return false; }); });
The effect is as follows:
4. Return to the array method
Background code:
[WebMethod] public static List "string" GetArray() { List "string" li = new List "string"(); for (int i = 0; i " 10; i++) li.Add(i + ""); Return li; }
JS code:
$(function() { $("#btnOK").click(function() { $.ajax({ type: "Post", url: "demo.aspx/GetArray", contentType: "application/json; charset= Utf-8", dataType: "json", success: function(data) { //Clear ul $("#list").html("") before inserting //Recursively get data $(data.d) .each(function() { //Insert the result into li $("#list").append("li"" + this + "/li"); }); alert(data.d); }, error: function(err) { alert(err); } }); //Disable button commit return false; }); });
Page code:
"form id="form1" runat="server"
"div"
"asp:Button ID="btnOK" runat="server" Text="Verify User" /"
"/div"
"ul id="list"
"/ul"
/form
Running result graph:
We provide many kinds of Titanium Diaphragm to meet the different needs of different customers, they are widely used in Hi-Fi speakers,professional audio,horn speakers,car speakers and other high-end products.
We are experienced in manufacturing and have strong capability.
Our products are popular in many countries and areas.
We have professional acoustical testing systems and instruments.
We promise to offer you highest quality and best service!
Titanium Diaphragms,Titanium Replacement Diaphragm,Replacement Diaphragms,Tweeter Voice Coils, tweeter diaphragms
Taixing Minsheng Electronic Co.,Ltd. , https://www.ms-speakers.com