$.ajax() success called, but will not run method

This is really puzzling me. Any idea why this would be happening?

This code does work:

            type: 'GET',
            dataType: 'json',
            url: 'http://localhost:3235/Users/searchUsers?callback=?&searchString=' + searchString,
            success: alert("Success")

This code does not:

            type: 'GET',
            dataType: 'json',
            url: 'http://localhost:3235/Users/searchUsers?callback=?&searchString=' + searchString,
            success: function(data){


The first snippet is bad syntax and shouldn't be used, you get the alert because it is called immediately, not on success.

There are only two reasons for you to not get the alert with the 2nd snippet.

  1. the server isn't returning a success status code, for example, it's either 404, 500, etc, not 200.
  2. The only other possibility is the jsonp being returned either isn't jsonp, or isn't valid jsonp.

Most likely you are confusing JSONP with JSON, so i'll give you an example of each. First is json:


and this is JSONP ...?callback=somecallbackname&...:


Note, somecallbackname will be supplied by jQuery, you'll have to get the value of the callback get parameter and use it to generate the JSONP accordingly.

Need Your Help

Android: How can I reliably detect every minute in time?

android timer

I need a reliable way to monitor minute-ticks in an Android app. This thread (in C#) .NET, event every minute (on the minute). Is a timer the best option? says that creating a timer that ticks every

How accessibility works inside for iOS?

ios jailbreak iphone-privateapi

Have you seen any information about internals of iOS accessibility?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.