search

Home  >  Q&A  >  body text

node.js - Why can’t jsonp get the desired content across domains?

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');
             }
         });
     });
伊谢尔伦伊谢尔伦2843 days ago506

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 13:36:18

    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>

    reply
    0
  • Cancelreply