Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6165611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:11:46+00:00 2026-05-23T22:11:46+00:00

In trying to use the stackoverflow api with ajax and jquery and I just

  • 0

In trying to use the stackoverflow api with ajax and jquery and I just can’t get it to work. I know I have to use jsonp as the datatype and I keep reading different ways of doing the jsonp request but I still can’t get it to work.

This is my ajax request:

var API_KEY = "XXXXXXXXXXXX";
var URL = "http://api.stackoverflow.com/1.1/";

var _url = URL + 'users?filter=locrizak';

$.ajax({
    dataType:'jsonp',
    jsonp : false,
    jsonpCallback : "onJsonp",
    url: _url,
    success: function(val) {
            console.log('success');
        //console.log(val);
    },
    error: function(val) {
        console.log('error');
        console.log(arguments);

    }
});

function onJsonp() {
    console.log(arguments);
};

No matter what I try I always get this response in firebug:

"parsererror" "onJsonp was not called"

I know that I am doing something really dumb because I ran into the same issues when trying to use the Twitter api but I can’t for the life of me remember what I did to get it to work.

Update

So I took a loog @genesis’s working demo and tried it a few time and different ways but no luck. Then I notice my jQuery version and switched it to the one he was using and it magically worked.

I change the most recent version
http://code.jquery.com/jquery-1.6.2.min.js
to
http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js

hmm no idea why it works, possibly a bug but who knows maybe something else changed.

If anyone knows why it would be awesome if you could explain. Also I realize that jQuery adds the callback automatically but I could not get it working like that. What could I do to get this working, I guess you would say a “more proper” way?

var URL = "http://api.stackoverflow.com/1.1/";
api.get(URL + 'users?filter=locrizak');
api.get = function(url) {
    $.ajax({
        /*dataType:'jsonp',*/
        dataType:'json',
        jsonp : false,
        url: url + '&jsonp=api.onJsonp',
        success: function(val) {
            console.log('success');
            //console.log(val);
        },
        error: function(val) {
            //error gets called but.......
            console.log(arguments);
            console.log('error');
            console.log(val);
        }
    });

};
api.onJsonp = function() {
    //so does the callback!!  
    console.log('called');
    console.log(arguments);
}
//note this code is simplified
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:11:48+00:00Added an answer on May 23, 2026 at 10:11 pm

    You can add jsonp:'jsonp', to the ajax() call. The stackoverflow API documentation states that it needs the jsonp query paramater and the jQuery property to configure the query string parameter passed is called jsonp. Without it, the default is to add callback=? to the end of the URL.

    I get success in the console, running this:

    var URL = "http://api.stackoverflow.com/1.1/";
    var _url = URL + 'users?filter=locrizak';
    
    $.ajax({
        dataType: 'jsonp',
        jsonp: 'jsonp', // <--- add this
        url: _url,
        success: function(val) {
           console.log('success');
        },
        error: function(val) {
            console.log('error');
            console.log(arguments);
        }
    });
    

    Also, jsonp:false, should not be set to false; it needs to be true otherwise no query string parameter is added.

    Update: Got it working correctly with jQuery v1.6.2 and using the correct parameters as described in my original answer above. The callback function must be outside the jQuery anonymous function.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>JSONP Test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function(){
                $.ajax({
                    dataType:'jsonp',
                    jsonp: 'jsonp',
                    jsonpCallback: 'onJsonp',
                    url: 'http://api.stackoverflow.com/1.1/users?filter=locrizak',
                    success: function(data) {
                        console.log('success', data);
                    },
                    error: function(data) {
                        console.log('error', data);
                    }
                });
            });
    
            function onJsonp(data) {
                console.log('callback', data);
            };
        </script>
    </head><body></body></html>
    

    Update 2: Based on comments, here is another version, this time wrapped in an object. Note that you cannot use jsonpCallback: 'api.onJsonp', because that is only defined inside the jQuery anonymous function. The simplest way to keep the encapsulation is to create a global function and just pass control back to the api counterpart.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>JSONP Test</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function(){
                api = {
                    get: function(url) {
                        var URL = "http://api.stackoverflow.com/1.1/";
                        $.ajax({
                            dataType: 'jsonp',
                            jsonp: 'jsonp',
                            jsonpCallback: 'onJsonp',
                            url: URL + url,
                            success: function(data) {
                                console.log('success', data);
                            },
                            error: function(data) {
                                console.log('error', data);
                            }
                        });
                    },
                    onJsonp: function(data) {
                        console.log('callback', data);
                    }
                }
    
                api.get('users?filter=locrizak');
            });
    
            function onJsonp(data) {
                api.onJsonp(data);
            }
        </script>
    </head><body></body></html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the stackoverflow API and I want to get answers of
I am trying to use LWP::Simple to make a GET request to a REST
I'm trying to use the new WCF Web API Preview 6 with Basic Authentication.
I'm trying to use Circumflex ORM (as suggested on StackOverflow - here , here
i am trying to use the API for sign in with Google account with
I'm trying to use the official jQuery autocomplete plugin with an ASMX web service
I have been navigating the various WebBrowser control stackoverflow questions , and I can't
I am trying to use JS (prefered) or PHP to access APIs like StackOverflow,
Trying to use federated authentication with AppEngine. I have implemented the authenication part but
I am trying to use symbolic links in one of the applications I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.