ASP.net MVC returning JSONP

Here is a simple solution, if you don’t want to define an action filter Client side code using jQuery: $.ajax(“http://www.myserver.com/Home/JsonpCall”, { dataType: “jsonp” }).done(function (result) {}); MVC controller action. Returns content result with JavaScript code executing callback function provided with query string. Also sets JavaScript MIME type for response. public ContentResult JsonpCall(string callback) { return … Read more

How do I catch jQuery $.getJSON (or $.ajax with datatype set to ‘jsonp’) error when using JSONP?

Here’s my extensive answer to a similar question. Here’s the code: jQuery.getJSON(handlerURL + “&callback=?”, function(jsonResult){ alert(“Success!”); }) .done(function() { alert(‘getJSON request succeeded!’); }) .fail(function(jqXHR, textStatus, errorThrown) { alert(‘getJSON request failed! ‘ + textStatus); }) .always(function() { alert(‘getJSON request ended!’); });

JSON string to JS object

Some modern browsers have support for parsing JSON into a native object: var var1 = ‘{“cols”: [{“i” ……. 66}]}’; var result = JSON.parse(var1); For the browsers that don’t support it, you can download json2.js from json.org for safe parsing of a JSON object. The script will check for native JSON support and if it doesn’t … Read more

jsonp with jquery [closed]

Here is working example: <html><head><title>Twitter 2.0</title> <script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script> </head><body> <div id=’tweet-list’></div> <script type=”text/javascript”> $(document).ready(function() { var url = “http://api.twitter.com/1/statuses/user_timeline/codinghorror.json”; $.getJSON(url + “?callback=?”, null, function(tweets) { for(i in tweets) { tweet = tweets[i]; $(“#tweet-list”).append(tweet.text + “<hr />”); } }); }); </script> </body></html> Notice the ?callback=? at the end of the requested URL. That indicates to … Read more

jQuery ajax (jsonp) ignores a timeout and doesn’t fire the error event

jQuery 1.5 and higher have better support for error handling with JSONP requests. However, you need to use the $.ajax method instead of $.getJSON. For me, this works: var req = $.ajax({ url : url, dataType : “jsonp”, timeout : 10000 }); req.success(function() { console.log(‘Yes! Success!’); }); req.error(function() { console.log(‘Oh noes!’); }); The timeout seems … Read more

Post data to JsonP

It is not possible to do an asynchronous POST to a service on another domain, due to the (quite sensible) limitation of the same origin policy. JSON-P only works because you’re allowed to insert <script> tags into the DOM, and they can point anywhere. You can, of course, make a page on another domain the … Read more

So, JSONP or CORS? [closed]

This is a pretty broad question, and could warrant a wiki unto itself. There is also quite a bit on google regarding the two, but I think I can hit a few key points. If you need a read-only ajax interface to your servers and you need to support IE<=9, Opera<12, or Firefox<3.5 or various … Read more

parsing JSONP $http.jsonp() response in angular.js

UPDATE: since Angular 1.6 You can no longer use the JSON_CALLBACK string as a placeholder for specifying where the callback parameter value should go You must now define the callback like so: $http.jsonp(‘some/trusted/url’, {jsonpCallbackParam: ‘callback’}) Change/access/declare param via $http.defaults.jsonpCallbackParam, defaults to callback Note: You must also make sure your URL is added to the trusted/whitelist: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)