jQuery AJAX and HttpHandlers in ASP.NET
https://www.codeproject.com/Articles/170882/jQuery-AJAX-and-HttpHandlers-in-ASP-NET
Introduction
In this article, we will see how we can make use of the jQuery library to make AJAX calls in ASP.NET with the help of HTTPHandlers. We will also see the use of JSON (JavaScript Object Notation) which is a format describing name/value pairs in a structured manner.
Asynchronous JavaScript and XML (AJAX) is a method which we can use to exchange data with the server without reloading the complete page.
jQuery is a JavaScript library which makes it easier to manipulate and navigate DOM elements in a web page. It also helps in implementing AJAX in rapid web application development. Currently, we have Intellisense support for jQuery in Visual Studio 2008/2010.
HTTPHandler is a process which returns data when its URL is called. The returned data can be anything from a simple string to data formats like JSON or XML.
Prerequisite
Download the latest version of jQuery from the jQuery site (http://jquery.com/). In Visual Studio 2010, it is added by default when a new web application is created.

Example: Making a Simple AJAX Call
In this example, we will make a simple AJAX call with the help of the jQuery.ajax API to an HTTPHandler.
The response from the HTTPHandler will be the JSON response which is then updated in the web page.
JavaScript Object notation (JSON) is a format of key/value pairs to store data.
It’s easy to consume in JavaScript and compact than XML. So let’s start with creating a handler page.
public void ProcessRequest (HttpContext context) {
string method = context.Request.QueryString["MethodName"].ToString();
context.Response.ContentType = "text/json";
switch (method)
{
case "GetData" :
context.Response.Write(GetData());
break;
}
}
protected string GetData()
{
return (@"{""FirstName"":""Ravi"", ""LastName"":""Baghel"",
""Blog"":""ravibaghel.wordpress.com""}");
}
As you can see, we are simply putting a response of JSON type with sample data.
In order to demonstrate passing a parameter to a handler, I have used the querystring methodname which will simply switch to the method you want to execute.
jQuery AJAX and HttpHandlers in ASP.NET的更多相关文章
- jQuery Ajax传递数组到asp.net web api参数为空
前端: var files = []; files.push({ FileName: "1.jgp", Extension: ".jgp", FileType: ...
- [转]jQuery AJAX pagination plugin with ASP.NET Server Side
本文转自:http://do-web.com/jpaging/usage How does it work? 1. In order to implement the plugin, you need ...
- jQuery AJAX Call for posting data to ASP.Net page ( not Get but POST)
the following jQuery AJAX call to an ASP.Net page. $.ajax({ async: true, type: "POST", url ...
- ASP.NET使用jQuery AJAX实现MD5加密实例
一个asp.net ajax例子,使用jquery,实现md5加密.在.NET 4.0,Visual Studio 2010上成功运行. 效果体验:http://tool.keleyi.com/t/m ...
- [转]JQuery Ajax 在asp.net中使用总结
本文转自:http://www.cnblogs.com/acles/articles/2385648.html 自从有了JQuery,Ajax的使用变的越来越方便了,但是使用中还是会或多或少的出现一些 ...
- jQuery Ajax 方法调用 Asp.Net WebService 以及调用aspx.cs中方法的详细例子
一.jQuery Ajax 方法调用 Asp.Net WebService (引自Terry Feng) Html文件 <!DOCTYPE html PUBLIC "-//W3C//D ...
- ASP.NET jquery ajax传递参数
第一种:GET传递 前台 ajax GET 传递 :即在请求的地址后面加上参数,URL地址长度有显示,安全性低 后台接收:Request.QueryString[“参数名字”]! 例如: func ...
- JQuery Ajax 在asp.net中使用小结
自从有了JQuery,Ajax的使用变的越来越方便了,但是使用中还是会或多或少的出现一些让人短时间内痛苦的问题.本文暂时总结一些在使用JQuery Ajax中应该注意的问题,如有不恰当或者不完善的地方 ...
- asp.net 中使用JQuery Ajax 上传文件
首先创建一个网页,网页中添加如下代码. <h3>Upload File using Jquery AJAX in Asp.net</h3> <table> < ...
随机推荐
- char数组初始化
初始化 char str[10]="Hello"; char str[10]={'H','e','l','l','o','\0'}; char str[10]={'H'}; cha ...
- ArrayList,linkedList vecator的实现和区别
1.线程安全问题. ArrayList 和 linkedList 线程是不安全的,而vecator是线程安全的. 因为ArrayList 和 linkedList 是线程不同步的,vecator是同步 ...
- XmlNode.PrependChild 方法
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { X ...
- python列表-使用
一.列表用于循环 1.for循环 2. in 和 not in 3.多重赋值
- python函数-基础知识
一.含义函数是程序内的“小程序” 二.示例 #!/usr/bin/env python #coding:utf-8 def hello(): print('Hello world!') print(' ...
- 《剑指offer》面试题16 反转链表 Java版
(输入链表的头节点,反转链表) 书中方法:对于一个链表,我们只能从头往后遍历,如果要反转,我们需要更改当前节点的next域指向前一个节点,此时链表断开,为了能继续修改下一个节点的next域,我们还要维 ...
- 搭建Eclipse+pydev+python2.7.5+django1.5.1+mysql5.0.45平台
mysqldb 下载地址 http://sourceforge.net/projects/mysql-python/ or https://pypi.python.org/pypi/MySQL-pyt ...
- unity2017 光照与渲染(一)
光照&渲染(基于unity2017.2.0) Custom Skybox 天空盒 最丰富的环境光 a. TextureShape 改成 Cube. b. 把图片直接丢给天空,就会自动生成材质. ...
- [python 学习] IO操作之读写文件
一.读取全部文件: # -*- coding: utf-8 -*- f = open('qq_url.txt','r'); print f.read(); f.close(); 二.读取规定长度文件 ...
- jmeter性能工具 之 传参 (三)
jmeter 主要有三种方式:键值对传参,json格式传参,外部传参 1.键值对传参 可以参考上篇登陆,使用的传参方式是键值对传参 2.json 格式传参 用json 格式传参不要忘了加http 头 ...