jsonp+handler 的实现
//参考 http://www.cnblogs.com/yuwensong/archive/2013/05/28/3103064.html
后台:
- public void ProcessRequest(HttpContext context)
- {
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
- //获取回调函数名
- string callback = context.Request.QueryString["callback"];
- //json数据
- string json = "{\"name\":\"chopper\",\"sex\":\"man\"}";
- context.Response.ContentType = "application/json";
- //输出:回调函数名(json数据)
- context.Response.Write(callback + "(" + json + ")");
- }
前台:
- function fnHello() {
- $.ajax({
- url: "http://172.16.74.102:88/WebAPI/LoginHandller.ashx",
- dataType: "jsonp",
- jsonpCallback: "person",
- data:{aaa:"1111"},//参数后台可以得到
- success: function (data) {
- alert(data.name + " is a a" + data.sex);
- }
- });
- }
- //回调函数person
- function person(data) {
- alert(data.name + " is a " + data.sex);
- }
jsonp+handler 的实现的更多相关文章
- 【highstock】按时间(zoom)让它去访问服务器呢?
$(function () { /** * Load new data depending on the selected min and max */ function afterSetExtrem ...
- 利用JQuery jsonp实现Ajax跨域请求 .Net 的*.handler 和 WebService,返回json数据
1:跨域请求handler一般处理程序 using System; using System.Collections.Generic; using System.Web; using System.W ...
- jQuery-1.9.1源码分析系列(十六)ajax——jsonp原理
json jsonp 类型 "json": 把响应的结果当作 JSON 执行,并返回一个JavaScript对象.如果指定的是json,响应结果作为一个对象,在传递给成功处理函数 ...
- jQuery源码分析系列(34) : Ajax - 预处理jsonp
上一章大概讲了前置过滤器和请求分发器的作用,这一章主要是具体分析每种对应的处理方式 $.ajax()调用不同类型的响应,被传递到成功处理函数之前,会经过不同种类的预处理(prefilters). 预处 ...
- JSONP浅析
DEMO : JSONP示例 为什么使用JSONP JSONP和JSON是不一样的.JSON(JavaScript Object Notation)是一种基于文本的数据交换方式,或者叫做数据描述格式. ...
- 跨域解决方案二:使用JSONP实现跨域
跨域的实现方式有多种,除了 上篇文章 提到的CORS外,常见的还有JSONP.HTML5.Flash.iframe.xhr2等. 这篇文章对JSONP的跨域原理进行了探索,并将我的心得记录在这里和大家 ...
- jsonp与ajax
jsonp思维导图:1.定义2.为什么用3.json原理4.优缺点何为跨域?何为JSONP?JSONP技术能实现什么?是否有必要使用JSONP技术? JSON和JSONP??虽然只有一个字母的差别,但 ...
- Jsonp 解决跨域问题
话不多说直接贴代码: $.ajax({ async: false, url: 'http://****.****.com/Handler.ashx?vueId=iwNavpicS2', type: & ...
- jsonp与cors跨域的一些理解(转)
CORS其实出现时间不短了,它在维基百科上的定义是:跨域资源共享(CORS )是一种网络浏览器的技术规范,它为Web服务器定义了一种方式,允许网页从不同的域访问其资源.而这种访问是被同源策略所禁止的. ...
随机推荐
- POJ burnside&&polya整理练习
POJ 2409 Let it Bead 这题就是polya公式的直接套用,唯一麻烦的是置换群的种类数,由于可以翻转,所以除了要加上pow(c,gcd(s,i))这些平面旋转的置换群,还要加上翻转的. ...
- [Docker] Install Docker on Windows (hp) and start with Kitematic
Well, on Windows costs a little bit effort to run docker. 1. You need to enable Virtulization: Oh hp ...
- [Angular 2] Build a select dropdown with *ngFor in Angular 2
We want the start-pipe more flexable to get param, so when using it, we pass a second param as statu ...
- 去除html页面中按钮在ios中的默认样式,去除select自带的小三角图标
btn{-webkit-appearance: none;} -webkit-appearance: none也能去掉select下拉列表后面自带的小三角
- .NET中使用GridView控件输入数据时出现“ Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"的问题
在.NET中使用GridView控件的在线编辑数据时,出现了“ Index was out of range. Must be non-negative and less than the size ...
- 《Boost程序库完全开发指南》读书笔记-日期时间
●timer库 #include <boost\timer.hpp> #include <boost\progress.hpp> 1.timer类 // timer类的示例. ...
- Sed命令学习
1.Sed简介 流数据编辑器 Stream editer(sed),它是一种行编辑器(对应于全屏编辑器),一次处理一行的内容.默认不编辑原文件内容(-i会直接修改原文件).处理时,它先将当前符 ...
- Retinex processing for automatic image enhancement 翻译
Retinex processing for automatic image enhancement 摘要: 最近六七年来,人们从新燃起了对Retinex computation的兴趣,特别是在它对图 ...
- C语言初学 简单定义圆的面积计算问题
#include<stdio.h> #define PI 3.14159 main() { double a; scanf("%lf",&a); printf( ...
- IOC容器MEF在MVC中的使用
最近想把自己的网站框架用IOC改造下,经过对比,我初步选择autofac,虽然MEF不需要配置,但性能不行,autofac虽然需要自己写自动化注入,但性能非常好. 先分析下各大IOC框架的性能,分两类 ...