加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax 跨域请求

发布时间:2020-12-15 21:51:42 所属栏目:百科 来源:网络整理
导读:Html: 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

Html:

  1. <scripttype="text/javascript"src="http://www.youxiaju.com/js/jquery-1.4.2.min.js"></script>

  2. scripttype="text/javascript">

  3. $(function(){

  4. $.ajax(

  5. {

  6. type:'get',

  7. url:'http://www.youxiaju.com/validate.php?loginuser=lee&loginpass=123456',

  8. dataType:'jsonp',

  9. jsonp:"jsoncallback",

  10. success:function(data){

  11. alert("用户名:"+data.user+"密码:"+data.pass);

  12. },

  13. error:function(){

  14. alert('fail');

  15. }

  16. }

  17. );

  18. })

  19. >


服务端:

  1. <?php

  2. header('Content-Type:text/html;Charset=utf-8');

  3. $arr=array(

  4. "user"=>$_GET['loginuser'],

  5. "pass"=>$_GET['loginpass'],

  6. "name"=>'response'

  7. );

  8. echo$_GET['jsoncallback']."(".json_encode($arr).")";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读