I am trying to get getJSON working on my IE, but I read that IE doesn't support it that well. So I decided to use ajax instead.
My code is:
$.ajax({
dataType: 'json',
url: 'http://openexchangerates.org/latest.json',
success: function(data)
{
alert('done');
}
});
Thanks
You cannot make crossdomain ajax calls. Take a look at the top post at this SO post. If you have a specific need to do so, you need to use some sort of sockets. This can be file_get_contents in php or another server-side language
I had this problem just the other day. Internet Explorer doesn't like you doing cross-domain requests with AJAX.
I solved it by having a server-side script do the cross-domain API request, and then call the result of that script in my AJAX call.
Related
I have created REST API in codeigniter. This API I am using on my codeigniter website and It's working fine. I have created one JavaScript for call API using ajax. It's also working fine but problem is that after calling ajax If refresh the page or tired to open another page of website it's send to me login page. I don't know why my session is expired ?
I have check in chrome developer tools. After calling ajax clicked page return 302 status.
$.ajax({
url: rest_url,
dataType: 'jsonp',
success: function(data){
//some code
}
});
This problem is caused by session ID regeneration during AJAX requests
If you upgrade your codeigniter , it will be good because we have fixed this error with codeigniter. If you can't , you can get a view in how we have fixed it here Fix of this bug in github. As you can see you just need to change the if condition on this file system/libraries/Session.php. I think that my answer will be usefull for you.
Help!
I am using jquery mobile to submit a JSON string to my rails app via an ajax post. The string contains some data that I send via the following ajax call in a JS file:
$.ajax({
url: "http://" + MyURL + ".json",
type: "POST",
data: JSON.stringify(this.form),
dataType: "json",
contentType: "application/json",
success: onSaveSuccess,
error: onFailure,
complete: onComplete
});
This code works, but as soon as I press the button to submit the form, it changes the page to my home page (NOT EVEN THE PREVIOUS PAGE). I want to set this post up so that it doesn't change pages until I tell it to (in either the success or complete functions). I don't want the user to be thrown around different pages after submitting the post. Instead, I want to show my upload spinner until it is done, and then I will redirect them to a specific page.
Does anyone know how to do this?
My login screen uses a (nearly) identical ajax script, and it does exactly what I want. I am assuming that is because there is no page to go "back" to. I don't understand this behavior, so if anyone does, your advice would be appreciated.
My site using Ajax to display the drop down model fields
When checked in mobile browser, due to ajax technology not supported by most mobile phones, the drop down model field does not appear and remain stagnant
Is there any way to change script to mobile friendly technology so that when someone views the page through mobile, the script can use that mobile friendly script
thnx
ajax not supported in mobile?? It is supported in major Operating systems such as iOS and Android.
I hope you are not programming for some old mobile browsers.
You can simply utilize the ajax functions in jQuery Mobile. I'm doing it for many of my projects.
A simple ajax call would look like below
$.ajax({
type: "POST",
url: url,
data: param,
contentType:"application/json; charset=utf-8",
dataType: "json",
success: successFunc,
error: errorFunc,
beforeSend:function(){$.mobile.loading( 'show' );},
complete:function(){$.mobile.loading( 'hide');}
});
In my Javascript heavy Web app, I have some scripts that are loaded in the source HTML with tags, and others that I load as needed using jQuery's ajax method.
I am in the process of relocating most of my app's static assets to a CDN (I'm using AWS Cloudfront). My dynamic loads no longer work. The jQuery Ajax call:
$.ajax({
url: url,
dataType: 'script',
async: true,
success: function (content) {
....
triggers the success function, but the content is empty.
I'm wondering if this is because such a request violates the Browser's security model for cross-site scripting. If that's the case, is there to load scripts dynamically from a CDN? Ahhh... I am NOT presently using a CNAME alias for the cloudfront host. Would doing so solve this problem?
You're right, it is the cross-site scripting security preventing this.
You're able to use the jQuery.getScript() method to load it from an external domain (or internal).
i have have a form in site A and want to submit the form to a script located in site B.
If i submit the form normally all works well. If i try something like the following all hell breaks loose (well actually, nothing really happens :D)
$('#gs_vote_button').click(function(){
$.ajax({
type: "POST",
url: 'http://www.siteB.com/process_form.php?param1=x;param2=y',
data: $("#gs_vote_form").serialize(),
success: function(data) {
$('#submit_error').html(data);
}
});
return false;
});
So, is it possible to submit a form to a script in a remote site, with ajax? I really need this, please help...
For security reasons, you cannot use AJAX to send a request to a different domain.
Instead, you can make submit normal <form> that targets an <iframe>. (Note that you would not be able to read the response)
Alternatively, if you have control over or cooperation with the remote site, you can use JSONP.