会员
众包
新闻
博问
AI培训
云市场
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
thrillerz
我的架构师之路
博客园
首页
新随笔
联系
订阅
管理
jQuery Ajax 简单的实现跨域请求
html 代码清单:
[html]
view plain
copy
<
script
type=
"text/javascript"
src=
"http://www.youxiaju.com/js/jquery-1.4.2.min.js"
>
</
script
>
<
script
type=
"text/javascript"
>
$(function(){
$.ajax(
{
type:'get',
url : 'http://www.youxiaju.com/validate.php?
loginuser=
lee&
loginpass=
123456',
dataType : 'jsonp',
jsonp:"jsoncallback",
success : function(data) {
alert("用户名:"+ data.user +" 密码:"+ data.pass);
},
error : function() {
alert('fail');
}
}
);
})
</
script
>
服务端 validate.php 代码清单:
[php]
view plain
copy
<?php
header(
'Content-Type:text/html;Charset=utf-8');
$arr =
array(
"user" =>
$_GET[
'loginuser'],
"pass" =>
$_GET[
'loginpass'],
"name" =>
'response'
);
echo
$_GET[
'jsoncallback'] .
"(".json_encode(
$arr).
")";
效果图:
posted @
2016-02-17 15:51
thrillerz
阅读(
152
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告