JQuery :: Make JSON Versus JSONP Request Depending On URL

Apr 21, 2010

So I have a function that is going to get a URL, and have to retrieve json data from that URL. The URL _might_ be same-domain, and might be cross-domain. If it's cross-domain, of course I want to do jsonp complete with the script-tag-to-load and such, but if it's same domain of course I want to do just xhr for efficiency. So I _could_ write all my own logic for this. Write logic to see if the url is cross-domain or not, and then make entirely different $.ajax() calls depending.

(I think I need to use $.ajax() rather than $.getJSON() because I need a callback on failure, not just success). If it is cross-domain, use dataType:jsonp, and make sure to supply a &callback. If it's not cross-domain, dataType:json, and don't even bother supplying a callback. But I'm having trouble figuring out if this is true, or how. What's the easiest way to get $.ajax() to make a dataType:json request if it's same-domain, but a dataType:jsonp request if it's cross-domain?

View 1 Replies


ADVERTISEMENT

JQuery :: Headers And Non JS Code Returned From JSONP Request?

Aug 6, 2010

Im trying to figure out if a public picasaweb userid exists or not. Its a pure client app, so no server-side proxies. The 1st method works only on FF & Chrome.

[Code]...

View 12 Replies View Related

JQuery :: .ajax() With DataType: 'jsonp' Will Not Use Error Callback If Request Fails?

Oct 1, 2009

I'm using an .ajax() call to do a jsonp request to another domain. When the user is not logged in, however, the server will return a 401 error. Unfortunately, this causes my .ajax() call to fail _without_ calling the error callback. Is this a known bug? Here is my code:

[Code]...

View 2 Replies View Related

Scope Of JSON Object In IE Versus Firefox

Aug 5, 2007

I'm a newbie to JSON and have been trying to parse some data and send it to a function that writes some html. I can do this in IE, but I can't get it to work in firefox. Code:

View 9 Replies View Related

JQuery :: Parse A Json Request ?

Sep 17, 2010

I am trying parse a json request.

The json response is

I have tried to console.log the item in a number of ways including: arrayToParse[item] item[1] item[0]

I either get the key of 1,2,3 or undefined. How do I get the values in this scenario?

View 2 Replies View Related

JQuery :: Updating Div From Json Request

Oct 23, 2011

Im updating a div with a ajax json dataType request i need the div to update to tne new request each time the option input is changed the problem is the div is updated but the first request is in it then the second then the third...so the div keeps on getting populated with each request how can i make so the div is polpulated with each request and not every request added to it? try with many stuff:append, remove but cant get it to work.

View 1 Replies View Related

JQuery :: Using Ajax Request With JSON Input

Nov 4, 2010

I have troubles with a simple jQuery.ajax-request which looks like this:
jQuery.ajax({
type: "GET",
url: "[URL]",
//url: "[URL]",
data: "",
success: function(data, status) {
$('body').html(data);
},
dataType: "json"
});

I test this with two different url's:
[URL]
[URL]
The first url works and I get json-data in the data-object. The second url gives a "parseerror", and I can't figure out why. As far as I can see (and using a json-validator) the second url returns valid json, so what's wrong?

View 2 Replies View Related

Jquery :: Json Response From An Ajax Request ?

Mar 28, 2011

I got a problem with a json response from an ajax request.

I have the following code :

Code:

And the called page (ajax_sous_famille.php) is giving me this result :

Code:

The info in the resulting string is correct, but here you can see the [ ] at the start and end of the line. It seems not to be a correct Json string and then it crashes my script !

I have another request like this which gives me the good format of resulting data (without the [ ]) and which works perfectly when i decode the Json string to display it.

The difference between the 2 requests is that the one which works returns only 1 array of values like

Code:

And the second one which doesn't work returns something like

Code:

Actually, all the records are coming from a database and in the case it doesn't work, i wanna get several results from this database.

View 7 Replies View Related

JQuery :: ParseJSON Parsing Error With JSON Request?

Apr 11, 2010

i'm trying to get a JSON-request from this API: h

[Code]...

View 1 Replies View Related

JQuery :: JSON - Refreshing Request Second Time After Page Loads

Oct 24, 2009

I'm using some jQuery to work with the Last.FM API, and I'm stuck where I need to allow the user to run the JSON request a second time after the page loads (it loads once automatically when the page loads, the second time is when they push a button). What happens currently, is the JSON function is fed some default data when the page loads:

$('#graph').lastFM({
username: 'UserName',
from: 1254369600,
to: 1256184000,
apikey: 'myApiKeyHere',
onComplete: function(){
//Done
}});

The JSON function:
$.fn.lastFM = function(options) {
var defaults = {
username: 'Verdani',
apikey: 'e4f3bb251d13179bf7ce80a089fb3d0c',
onComplete: function(){}
},
settings = $.extend({}, defaults, options); .....

You might have noticed in the JSON, I write the URL the JSON is requesting to the console every time it runs. When I click this button, a new URL pops up in the console below the first one but only for a second, and then the page reloads and the original JSON request is called. It's this loop that I can't seem to break out of - why does re-calling the JSON refresh the page?

View 1 Replies View Related

JQuery :: JSON Request To Get Data Back From A PHP File - For Loop + Append / AppendTo

Oct 1, 2010

I am doing a JSON request to get data back from a PHP file. On the return of that data, I am using a for loop to go through the data and post it up using JS. Here is my code:

for (var x = 0; x < data.length; x++) {
//create a container for each comment
var div = $("<div>").addClass("entry round").appendTo("#characters");
//add author name and comment to container
$("<div>").addClass("details").appendTo(div);
$("<span>").addClass("main-armory button").appendTo("div.details");
}

Now, what is happening, because there is 10 entries being posted, my JS is looking at the class that is being put together (main-armory button) and making it so that class appends every run through. So, I want one entry for main-armory button and I am getting this:

<div class="details"><span class="main-armory button"></span><span class="main-armory button"></span><span class="main-armory button"></span><span class="main-armory button"></span><span class="main-armory button"></span><span class="main-armory button"></span><span class="main-armory button"></span><span class="main-armory button"></span><span class="main-armory button"></span><span class="main-armory button"></span></div>

And then, when it goes down to the next entry, it has 9 spans, and then the next entry has 8 spans, and it continues all the way down. What is going on here that I am missing? I know that I am not clearing a variable properly or something is wrong within my loop.

View 3 Replies View Related

JSON Get Request Not Recognized?

Oct 13, 2011

The following request isn't retrieving a response when I look for it in Firebug. Any ideas why?

$function(){
//json request to flickr
$.getJSON('http://api.flickr.com/services/rest/?&method=flickr.photosets.getPhotos&api_key=71282ef5623d61a898f798c7916bed31&photoset_id=72157627882181032&format=json&jsoncallback=?'),
});

View 1 Replies View Related

Send Json As Ajax Request To Server

Aug 14, 2007

whats the best way to pass a json string to the server.

if my jsonstring = {a:&#391;',b:'sds',c:'sdg'}

could i send that to the server passing it as 1 variable like so:
url = /serverside.php?json=jsonstring

or would i have to break it down into something like this:
url = /serverside.php?a=1&b=sds&c=sdg

View 2 Replies View Related

AJAX :: Request + Pass Json Objects To The Server? - Firefox Error: No Element Found

Feb 8, 2010

I'm making this ajax call:

Code:
url = "/GeoAdaptaApp/geoLogger/logGuiEvents?json="+aLotOfJSONStuff;
encUrl = encodeURI(url,"UTF-8");
new Ajax.Request(encUrl, {
method: 'get',
onSuccess: this.sendQueueToServerSuccess( this,logConsole ),
[Code]...

The JSON string seems correct (I checked it with a validator) and it worked on an Ajax.updater (but i need a request now). Firefox keeps telling me:

[Code]...

The call always end up in the onFailure block. Full request here: [URL] It's very strange, Is there a better way to pass json objects to the server?

View 1 Replies View Related

JQuery :: Make Elements Inserted By AJAX Request Respond To Events?

Feb 24, 2010

Using $.get() and insertBefore() work great for what I'm doing. But, the data I insert does not respond to events that I have set up. I'm notsurprised by this. I'm sure there is something extra I need to do. But, what is that?

View 4 Replies View Related

AJAX :: Make POST Request Not Working In IE Browsers?

Aug 13, 2009

I have this code w/c makes a post request.

Code:
// start ajax code
var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;

[Code]...

View 6 Replies View Related

JQuery :: Create Ajax Request & And Edit Html Request

Jun 2, 2009

I worked with now in jQuery. Property however at present the following problem: [i]I provide a AJAX Request. the side is loaded, the parameters all conveyed and back receives I a complete HTML side. Now I would like to have only certain elements however from this side, like DIV, SPAN etc. How can I make with the AJAX Request return in such a way best, which I can select these elements thereby? Simply it would be unfortunately not functioned over the function $ (element), it even if I indicate the HTML Request as secondly parameter.[/i] Excused, for my bad English. ;-) Translatertool. There is unfortunately too many words, in order to describe my problem. ^^

View 2 Replies View Related

JQuery :: Jsonp To A Static Remote File?

May 12, 2009

Currently I was able to load remote JSON (php) file using JSONP protocol. However, how to do if my remote file is static? In the doc, it said: you can load JSON data located on another domain if you specify a JSONP callback, which can be done like so: "myurl?callback=?". But since my remote file is a static text file, how can I specify the callback in the output dynamically? In fact, I also wonder if it is possible to control the random callback name by modifying jquery source code...

View 1 Replies View Related

JQuery :: JSONP Ajax Call Never Returns?

Jul 28, 2011

I'm trying to use $.ajax to make a JSONP call, but the callback function is never executed.I have debugging code in my server that acknowledges that a request is received, but that never runs.The same URL works fine if I paste it into the address bar of my browser.

[Code]...

View 7 Replies View Related

JQuery :: Classic ASP And JSONP Output - Return Data

Jun 25, 2011

I found this post: [URL] It explains exactly what I want to do. The person who had the problem seemed to have sorted it out but as my knowledge is not to great I am not to sure what he is getting at. I tried various things but to no avail. All I want to do is return data to a calling javascript using type get and datatype jsonp. If I simply Response.Write "[(""id"": ""123""}]" then nothing happens. So whatever the thread I revered to above is doing it seems to be going in the right direction.

View 6 Replies View Related

JQuery :: Jsonp (firebug)returns Missing ; Before Statement?

Mar 30, 2011

Here's my code:

$( document ).ready( function(){
$('#get_metars').click( function(){
//var icao = $('#icaos').val();

[code]....

View 1 Replies View Related

JQuery :: JSONP And Asynchronous - Capturing And Returning Response?

Mar 17, 2010

If this is synchronous, normal json request, I can capture the result (data) and return it to a calling function.

However jsonp is not synchronous. Whilst the data IS returned, and I can view it from within the success function, but I cannot access it after that.

$.ajax({
url: remote_url,
async: false,
cache: false,

[Code]....

I am building a library of functions which call this function, so I cannot have the data processing done within the success function, I need to extract the data itself.

View 2 Replies View Related

JQuery :: Jsonp Callbacks Execution Order In Firefox

Apr 6, 2010

I am trying to develop a iGoogle-like dashboard that uses JSONP to get the content of each widget from other (trusted) sites.Each widget is a div that will take care of getting its content using $.ajax() and use the callback to update the div with the html content returned with JSONP.The problem I have happens only in Firefox (I'm using 3.6.3):when a site is unavailable or takes longer to return the JSONP content for a widget, it seems that the callback for the other widget does not get executed. All the widgets stay in the "loading" state although I'm sure they have all received the answer.What's puzzling is that if I hit the "stop" button of Firefox, the content of the other widgets get displayed (ie. their displaying callbacks get executed).

If the calls are asynchronous, what prevents Firefox from executing the callbacks for the other widgets once the response is received?Do you have any idea of what's happening and if there's some way around this?

View 2 Replies View Related

JQuery :: JSONP - Error / Complete Event Not Firing

Jun 27, 2011

I have some jQuery making ajax requests that works just fine if the server returns a 200 but whenever it returns any error HTTP status none of the events fire. It's happening on more than one request to different servers but I'll just include one example for now:

var ajaxResponse = $.ajax({
url: widget.serviceURL + 'customer/createAjax?'+$('#ndBookingFormStep1').serialize(),
dataType: 'jsonp',
success: function(data, textStatus, jqXHR){
console.log(data);
if( data.status != 'OK'){
widget.message(data.status);
} else {
console.log(data);
}}})
.error(function(jqXHR, textStatus, errorThrown){
console.log(jqXHR);
}).complete(function(jqXHR, textStatus){
console.log(jqXHR);
});
console.log(ajaxResponse);
console.log(ajaxResponse.responseText );

The request gets made just fine, I can see the response in the net console in firebug and it returns the data I want with a 500 when I do not complete the form correctly. However, it does not fire either the error or the complete function when I get this status, and the ajaxResponse.responseText is undefined when it is logged to the screen. When the form is completed and the request is successfull the success function fires just fine.

View 8 Replies View Related

JQuery :: Link Tracking Plugin + JSONP + Opera?

Oct 1, 2009

I'm tryng to develop a link tracker, something like google analytics. The goal is to get a command like this:

$('html').trackAllLinks(optional options);
$('a').trackAllLinks(optional options);

Now i developed a javascript that could do just what i need but the problem is it doesn't work in every browser as it should be. Because i want to track a link click i need to make a request to my server to say that the link has been clicked. The first problem i had was that i needed to make a cross domain ajax call. But this is fixed by using JSONP. Now my code looks like this:

[Code]...

The first idea was that i wouldn't do anything in the success of the jsonp call and just let the request go, but because this didn't work when i clicked on an external link, i changed it to wait on a response before opening the link. The problem with this code is that it doesn't work in Opera, no request is being send to the server Now i know that JSONP mimics the ajax call by adding a script tag to the page which loads the script of the given url. Now i think when i do this in Opera the dynamically loaded javascript isn't executed. In Firefox, IE, Chrome, Safari it works but not in Opera.

Another idea i had was by dynamicly adding an image to the page. But this has the same problem in Opera and i was unable to track an external link in Safari and Chrome (Webkit.

View 1 Replies View Related

JQuery :: Ajax Call Doesn't Get Jsonp It Expects?

Sep 30, 2011

I have jQuery 1.5.1 client-side that is making an .ajax() call to an ASP.Net MVC controller method - expecting a jsonp packaged response. In normal cases, the server packages up a response of typeapplication/json and that works fine. The problem is when the session on the server times out, the server will respond to the ajax call with the server's login page, which obviously isn't valid json and the error handler on the ajax call fires with a parseerror. Similarly, if there's an exception server-side, the site redirects to a custom error page, which again isn't valid json, and: barf. I have no information client-side what went wrong when in the .ajax error handler. The xhr just says parseerror with no further info. Is there any way I can see what the server responded with so I can handle this more intelligently? I've tried change the client-side dataType to "json text" hoping that it would try to interpret the server response as text, if the json fails, but it just goes to the error handler.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved