devendra tata devendra tata - 6 days ago 6
jQuery Question

Uncaught SyntaxError: Unexpected token : select?fq=id:*dev*&fq=org_id:21&indent=on&q=*:*&wt=json&callback=jQuery2030069…_148048



$.ajax({
type: 'GET',
dataType: 'jsonp',
url: 'http://localhost:8983/solr/hruser/select?fq=id:*dev*&fq=org_id:18&indent=on&q=*:*&wt=json',

success: function(data) {
console.log(data)

}
});





Response : 200ok
but error Uncaught SyntaxError: Unexpected token :

Answer

Add the json.wrf parameter to your query string, giving it the name of your callback function.

So your new ajax call will look like this.

 $.ajax({
                        type: 'GET',
                        dataType: 'jsonp',
                        url: 'http://localhost:8983/solr/hruser/select?fq=id:*dev*&fq=org_id:18&indent=on&q=*:*&wt=json&json.wrf=callbackfunction',
                        jsonpCallback:'callbackfunction',
                        success: function(data) {
                            console.log(data)

                        }
                    });

Then you can define your callback function like

function callbackfunction(data) {
        console.log(data );
    }

Note : callback can be anything ,it’s just the name of the callback to call, so json.wrf=blah will work too. jQuery will autogenerate a name for you, so you don’t need to worry about it.

Comments