node.js - Why can't jsonp get the desired content across domains?
伊谢尔伦
伊谢尔伦 2017-05-16 13:34:18
0
1
448

I have seen blog examples and tried cross-domain successfully.
I used nodejs to simulate it and changed it to a local address. Why can’t I get the content in zanNum?
Nodejs opens the configuration without any problem.
Result: alert(‘fail’)


$(function(){ 
        $.ajax({
             type: "get",
             async: false,
             url: "http://192.168.191.1:3000/zanNum",
             dataType: "jsonp",
             jsonp: "callback",
             jsonpCallback:"response",
             success: function(response){
                 alert(response);
             },
             error: function(){
                 alert('fail');
             }
         });
     });
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
我想大声告诉你

The methods of using get and post with jsonp are given in , please refer to

<script>
$(document).ready(function(){ 
    $("#search").click(function(){ 
        $.ajax({ 
            type: "GET",     
            url: "http://127.0.0.1:8000/ajaxdemo/serverjsonp.php?number=" + $("#keyword").val(),
            dataType: "jsonp",
            jsonp: "callback",
            success: function(data) {
                if (data.success) {
                    $("#searchResult").html(data.msg);
                } else {
                    $("#searchResult").html("出现错误:" + data.msg);
                }  
            },
            error: function(jqXHR){     
               alert("发生错误:" + jqXHR.status);  
            },     
        });
    });
    
    $("#save").click(function(){ 
        $.ajax({ 
            type: "POST",     
            url: "http://127.0.0.1:8000/ajaxdemo/serverjsonp.php",
            data: {
                name: $("#staffName").val(), 
                number: $("#staffNumber").val(), 
                sex: $("#staffSex").val(), 
                job: $("#staffJob").val()
            },
            dataType: "json",
            success: function(data){
                if (data.success) { 
                    $("#createResult").html(data.msg);
                } else {
                    $("#createResult").html("出现错误:" + data.msg);
                }  
            },
            error: function(jqXHR){     
               alert("发生错误:" + jqXHR.status);  
            },     
        });
    });
});
</script>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!