温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Ajax 跨域请求

发布时间:2020-07-08 10:50:21 来源:网络 阅读:355 作者:Jinl_bm 栏目:web开发

Html:

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

  2. <script type="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. </script>


服务端:

  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. );  

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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI