Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

jquery - jsonpCallback function not working

UPDATE 1:

I've just upgraded from jquery 1.4.4 to 1.6.1. How does that effect the script in the original question?

ORIGINAL QUESTION:

Just as I test, I did:

$(document).ready(function() {
    get_jsonp_feed();

    function get_jsonp_feed() {
        $.ajax({
            url: 'http://www.remote_host.co.uk/feed.php',
            type: 'GET',
            dataType: 'jsonp',
            jsonp: 'callback',
            jsonpCallback: 'jsonpCallback',
            error: function(xhr, status, error) {
                alert("error");
            },
            success: function(jsonp) { 
                alert("success");
            }
        });
    }

    function jsonpCallback(data){
        alert("jsonpCallback");
    }
});

I was expecting to get 2 alerts, the first showing success and the second showing jsonpCallback. But I am only getting the first alert success. Why is the second alert not showing up?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should change:

jsonp: 'callback',

to

jsonp: false

to override the default callback value.

See: http://api.jquery.com/jQuery.ajax/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...