您的位置:首页 > 其它

关于使用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>

然后

http://xxx.com/1.asp
就返回json数据:

response.Write(" showPrice({""success"":true,""result"":""ok""}) ")

记得使用showPrice()函数包含json数据

刚刚测试出来,记录起来以免以后忘记了
4000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: