Fernandes
Fernandes

Reputation: 216

Ext.util.JSONP.request always return "Uncaught ReferenceError: callback is not defined"

I'm trying to login in sencha using another server. The following code doesn't work and I don't know why. Always appears the same error: "Uncaught ReferenceError: callback is not defined" in console.

Ext.util.JSONP.request({ 
    url: 'http://myserver/api/v1/login-jsonp2/1',
    callback: function(data) {
        if (data) {
            console.log(data.results); 
            console.log('SUCCESS'); 
        } else {
            console.log('ERROR'); 
        }
    } 
});

Return: callback({"id":10,"username":"e002102","firstname":"Roberto","lastname":"Moussalli"})

I also try change the return to: {"id":10,"username":"e002102","firstname":"Roberto","lastname":"Moussalli"} But I received another error: "unexpected token"

The content-type of response is text/javascript And I also put in index.html the tag

< script src="http://myserver/api/v1/login-jsonp2/1?callback=callback"></script>

and

< script src="http://myserver/api/v1/login-jsonp2/1?callback=callback1"></script>

What is wrong?!?!

Upvotes: 0

Views: 929

Answers (1)

arthurakay
arthurakay

Reputation: 5651

Ext.data.JSONP.request will send an HTTP parameter with an auto-generated "callback" parameter which is unique to each request.

Therefore your server needs to change it on each request (see the PHP example in the API docs I linked).

    callback1({ "foo" : "bar" });
    callback2({ "foo" : "bar" });
    callback3({ "foo" : "bar" });

Upvotes: 2

Related Questions