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> < ...
随机推荐
- c# asp.net uploadify 上传大文件 出现的 HTTP 404 问题
用uploadify在IIS6下上传大文件没有问题,但是迁移到IIS7下面,上传大文件时,出现HTTP 404错误. 查了半天,原来是IIS7下的默认设置限制了上传大小.这个时候Web.Config中 ...
- python3爬虫之urllib初探
urllib主要包含request(请求模块).error(异常处理模块).parse(工具模块).robotparser(识别网站的robots.txt文件,是否允许爬取). request(请求模 ...
- [Web 前端] 005 html 常用标签补充
少废话,上例子 1. 正常的字 <br> <tt>小一点的字体</tt> <br> <small>变小</small> < ...
- SpringMvc错误:HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is n
HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemExc ...
- SQL取年月日的不同格式
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM Select CONVERT(varchar(100), GETDATE( ...
- linux安装mysql(tar.gz)
1. 查看卸载自带的mysql # rpm -qa|grep MySQLMySQL-X.X.X#rpm -e MySQL-X.X.X # rpm -qa|grep mariadb #有些版本还得查看卸 ...
- [Luogu 4688] [Ynoi2016]掉进兔子洞 (莫队+bitset)
[Luogu 4688] [Ynoi2016]掉进兔子洞 (莫队+bitset) 题面 一个长为 n 的序列 a.有 m 个询问,每次询问三个区间,把三个区间中同时出现的数一个一个删掉,问最后三个区间 ...
- Python 内置函数raw_input()和input()用法和区别
我们知道python接受输入的raw_input()和input() ,在python3 输入raw_input() 去掉乐,只要用input() 输入,input 可以接收一个Python表达式作为 ...
- MVC调用函数function.php
<?php //控制器的调用函数C function C($name, $method){ require_once('/libs/controller/'.$name.'Controller. ...
- IE, Chrome和Firefox浏览器 差异对比
最近的项目中使用Extjs5.6, 其中主要的一个特点就是js文件的动态加载,之前使用Firefox浏览器对js文件进行调试,打断点时,只对当次调试有效,刷新之后,由于动态加载的js文件(文件名后面加 ...