关于使用jq的ajax通过josnp方式跨域获取数据
2016-05-11 17:44
615 查看
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<SCRIPT src="/skin/skin_qide/js/jquery-1.7.2.min.js" type=text/javascript></SCRIPT>
<script>
$(function(){
$(document).on('click','.button2',function(){
$.ajax({
url: "http://xiangxinghua.localhost:8088/1.asp",
jsonpCallback: "showPrice",
jsonp: "callback",
dataType: "jsonp",
data: {
},
// work with the response
success: function( data ) {
console.log( data ); // server response
alert('我是本地函数,远程js带来的数据是:' + data.success);
}
});
});
});
</script>
</head>
<body>
<input type="button" value="提交" id="button2" class="button2"/>
</body>
</html>
然后
response.Write(" showPrice({""success"":true,""result"":""ok""}) ")
记得使用showPrice()函数包含json数据
刚刚测试出来,记录起来以免以后忘记了
4000
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<SCRIPT src="/skin/skin_qide/js/jquery-1.7.2.min.js" type=text/javascript></SCRIPT>
<script>
$(function(){
$(document).on('click','.button2',function(){
$.ajax({
url: "http://xiangxinghua.localhost:8088/1.asp",
jsonpCallback: "showPrice",
jsonp: "callback",
dataType: "jsonp",
data: {
},
// work with the response
success: function( data ) {
console.log( data ); // server response
alert('我是本地函数,远程js带来的数据是:' + data.success);
}
});
});
});
</script>
</head>
<body>
<input type="button" value="提交" id="button2" class="button2"/>
</body>
</html>
然后
http://xxx.com/1.asp就返回json数据:
response.Write(" showPrice({""success"":true,""result"":""ok""}) ")
记得使用showPrice()函数包含json数据
刚刚测试出来,记录起来以免以后忘记了
4000
相关文章推荐
- linux下让tomcat以service方式运行
- Qt中的json解析和处理 (使用的是qt5 版本)
- Lua中的ipair 和 pair的区别
- SaaS系列介绍之十三: SaaS系统体系架构
- linux下的tomcat jvm内存
- IE8下String的Trim()方法失效的解决方法
- 数据采样与处理算法
- 欢迎使用CSDN-markdown编辑器
- select(poll)系统调用实现解析(一)
- LeetCode 213
- Linux命令行下常用的快捷键
- NGUI的UISprite动态染色的一种方法
- 在Linux上安装postgresql
- SHA1算法升级SHA256更新计划
- java 获取程序执行时间
- thinkphp I()方法参数含义,新手要常用
- 性能更好的js动画实现方式——requestAnimationFrame
- MVC 4 异步编程简化了
- 数据访问......简单练习
- python计算文件的md5值