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

How to use jquery to implement ajax under asp.net

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

In this article Xiaobian for you to introduce in detail "how to use jquery to achieve ajax under asp.net", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use jquery to achieve ajax under asp.net" can help you solve your doubts.

First create an empty asp.net web application known as Ajax, as shown in the following figure.

Among them, the .ashx file is a general processor, so you don't need to know what it is for now. You'll see later.

First of all, let's sort out the functions we want to achieve: the WebForm1 page sends a request to the Handler1 processor every second, the Handler1 returns the data to the WebForm1 page, and the WebForm1 page is partially refreshed through ajax technology.

First, take a look at the main code of Handler1:

Public void ProcessRequest (HttpContext context) {Random rand = new Random (); int num = rand.Next (1m 10); context.Response.Write (num);}

The main purpose of this is to change the ProcessRequest method to the above look to generate a random integer of 1 to 9 and return it to the request page.

Let's take a look at the main code of WebForm1.aspx:

$(document) .ready (function () {function get () {$.ajax ({type: "Post", url: "Handler1.ashx", data: "", success: function (data) {$("# dataShow") .text (data)) });} setInterval (get, 1000);})

If we want to use jquery, we have to refer to the jqury-1.7.1.js file we just downloaded. The following code should be able to understand, right? If you don't understand this, you have to replenish the foundation of js first.

Add a line of code to the page:

Is used to display the data returned by the request Handler1.

After reading this, the article "how to use jquery to achieve ajax under asp.net" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

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