Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the steps of the ajax request

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Ajax request steps are what, I believe that many inexperienced people are helpless about this, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Five Steps to Ajax Requests

The first step is to create an XMLHttpRequest object.

Step 2: Register the callback function

Step 3, configure the request information, open(),get

Step 4: Send the request,post the parameters to be passed here.

Step 5: Create a callback function

//first step, create XMLHttpRequest object var xmlHttp = new XMLHttpRequest();function CommentAll() { //Step 2: Register the callback function xmlHttp.onreadystatechange =callback1; //{ // if (xmlHttp.readyState == 4) // if (xmlHttp.status == 200) { // var responseText = xmlHttp.responseText; // } //} //Step 3, configure the request information, open(),get //get request parameters after url,.ashx? methodName = GetAllComment&str1=str1&str2=str2 xmlHttp.open("post", "/ashx/myzhuye/Detail.ashx? methodName=GetAllComment", true); //post Request header information needs to be configured under request //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //Step 4, send request,post request, parameters to be passed here xmlHttp.send("methodName = GetAllComment&str1=str1&str2=str2");//"}//Step 5, create callback function function callback1() { if (xmlHttp.readyState == 4) if (xmlHttp.status == 200) { //Get the returned data var data = xmlHttp.responseText; //json string to json format data = eval(data); $.each(data, function(i, v) { alert(v); }); }}

background method

private void GetAllComment(HttpContext context) { //Params can get values passed in get and post. string methodName = context.Request.Params["methodName"]; //QueryString can only get the value passed in the get mode. string str1 = context.Request.Form["str1"]; //Get the value passed from httpRequest, including get and post methods string str2 = context.Request["str2"]; List comments = new List(); comments.Add(methodName); comments.Add(str1); comments.Add(str2); //ajax accepts json type and needs to transfer the returned data to json format. string commentsJson = new JavaScriptSerializer().Serialize(comments); context.Response.Write(commentsJson); After reading the above, do you know what the steps of Ajax request are? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report