zoukankan      html  css  js  c++  java
  • jquery ajax跨域

    jquery+ajax+jsonp实现跨域

    JS代码,需要引入jquery

    $(function(){  
        $.ajax({  
            type:'get',  
            url : 'http://kuayu.a.com/c.php?loginuser=lee&loginpass=123456',  
            dataType : 'jsonp',  
            jsonp:"jsoncallback",  
            success  : function(data) {  
                alert("用户名:"+ data.user +" 密码:"+ data.pass);  
            },  
            error : function() {  
                alert('fail');  
            }  
        });  
    });

    PHP代码

    header('Content-Type:text/html;Charset=utf-8');  
    if(!empty($_GET['loginuser'])){
        $arr = array(  
            "user" => $_GET['loginuser'],  
            "pass" => $_GET['loginpass'],  
            "name" => 'response'  
        );  
        echo $_GET['jsoncallback'] . "(".json_encode($arr).")";  
        die();
    }
  • 相关阅读:
    3.31上午英语视频
    3.30上午
    leetcode 38
    leetcode 36
    leetcode 28
    leetcode 27
    leetcode 26
    leetcode 24
    leetcode 21
    leetcode 20
  • 原文地址:https://www.cnblogs.com/phpyangbo/p/6431472.html
Copyright © 2011-2022 走看看