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 7765119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:05:35+00:00 2026-06-01T15:05:35+00:00

I have the following code to make a jsonp call. var contacts; $.ajax({ url:

  • 0

I have the following code to make a jsonp call.

  var contacts;
     $.ajax({
                            url: "http://localhost:51973/Service1/GetContacts",
                            type: "GET",
                            async: false,
                            data: { companyName: company },
                            dataType: "jsonp",
                            success: function(data) {
                                contacts = data;
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                alert("error " + XMLHttpRequest.statusText);
                            }
                        });

but for whatever reason I get the contacts as undefined. I inspected the traffic using fiddler and I found the it was getting the following response.

HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 09 Apr 2012 14:52:33 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 100
Cache-Control: private
Content-Type: application/x-javascript
Connection: Close

jQuery17107471185381512466_1333983153278([{"Email":"john@test.com","Name":"Test Company"}]);

so why is contacts variable not being set properly?

  • 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-06-01T15:05:36+00:00Added an answer on June 1, 2026 at 3:05 pm

    I would guess that you are trying to use the contacts variable right after the ajax call. You cannot do that. The ajax call is asychronous and thus completes sometime AFTER the ajax call completes. When it completes, the success handler is called. You need to put any code or any function calls that actually use the contacts information inside the success handler. This is asynchronous programming and you have to code it differently.

    success: function(data) {
        contacts = data;
        // put your code or function calls here that use the contacts data
    },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery (1.7.0) to make a json/ajax call to Spotify. The following code
I have the following code: $.ajax({ type: POST, url: url, data: sendable, dataType: json,
I have the following code where I make an copy of my database that
I have the following code to validate two text box entries to make sure
I have the following code; I want to make sure that submit does not
What do I have to change in the following code to make the A
i have the following code on my aspx page: jQuery(#listFondos).jqGrid({ url: '/PorMyController/LoadGridData/', datatype: 'json',
I have the following code: $('#DoButton').click(function (event) { event.preventDefault(); $(input:checked).each(function () { var id
I borrowed the following code to try to make an ajax-enabled WCF service work
i have the following basic script to make an api call to vimeo and

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.