Mui + jsonp cross-domain access Uncaught SyntaxError: Unexpected token

Plugin description: As we all know, the use of cross-domain ajax directly initiate problem-free access to the request, this time need to use jsonp protocol (unofficial protocol) processing, jQuery in . A J A X square method is also directly connected to branched supported so with the Association Protocol feed line cross -domain access to ask . The surface of the first first dielectric introduce make use J Q U E R & lt Yof .ajax domain access method, and then introduces other jQuery plugin (jQuery-JSONP) to achieve like functionality.
1, js page

code>
function login(){
    var ip="http://192.168.31.6:8080/HTML_ht";
    $.ajax({ 
        type:"GET",  
        url:ip+"/login.jsp",  
        crossDomain: true,  
        data:{   
            username:'admin',
            password:'123',
        },  
        dataType:'JSONP',  
        jsonp:"callback",  
        async:true,  
        success:function(data){ 
           var username = data.username;
           var password = data.password;
           if(username=="admin" && password=="123"){
                alert("登陆成功");
           }else{
                alert("登陆失败");

2, h5 page

<code>
<div class="container">
        <input type="text" name="username" id="username" />
        <input type="password" name="password" id="password" />
        <input type="button" value="Login" onclick="login()"/>
</div>


3, background processing

public void testjson(HttpServletRequest request, HttpServletResponse response) {  
    String callback = (String)request.getParameter("callback");  
    String jsonData = "{\"id\":\"3\", \"name\":"zhangsan", \"telephone\":"13612345678"}";//为了演示效果,json数据是写死的  
    String retStr = callback + "(" + jsonData + ")";  
    response.getWriter().print(retStr);
    }

Guess you like

Origin blog.csdn.net/l3922768721/article/details/78095050