How to convert Ajax to Mobile Friendly Script/Jquery - ajax

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');}
});

Related

Unable to Successfully Update Page Content via ajax

I have a mobile version of a website built in jQuery mobile and living on a dedicated "m.myurl" subdomain. The full desktop version of the site is in Wordpress. My goal is to have updates entered via Wordpress to the desktop site to show up dynamically on the mobile site as well. I am generating the page content from the individual pages of the desktop site via JSON feeds, and have confirmed that the JSON feeds are good (i.e.: if I enter their URL into a browser, I get a good JSON object). However, the AJAX call on the jQuery mobile site refuses to work. I have debugged to the point that I am not receiving any errors in my console, but when I attempt to log the response from the AJAX call to troubleshoot, it consistently shows in the log as undefined, so I am not receiving known good JSON objects.
The functions I'm using to make the AJAX call are as follows:
function processResponse(response){
var update = $(response).find('content');
$('.content').append($(update).html());
};//ends processResponse
function processJSON(url){
$.ajax({
url: url,
data: null,
success: processResponse,
dataType: 'jsonp',
});//ends ajax
};//ends processJSON
I've set the three JSON URL's equal to variables, but have tried calling the function with the URL passed in instead of the variable, to no effect. The 'processJSON" function is called within the content div of each page section of the jQuery mobile index.html file within a $(document).ready.I'm using 'jsonp' as the dataType, as I assume that calling from a subdomain to a main-level domain would be considered a cross-domain call. That said, I'm trying to get this to work locally, and haven't placed it on a test server yet.
Any assistance is appreciated. Thanks!

How to avoid a changePage immediately after ajax post with javascript

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.

getJSON and ajax not working in IE

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.

Ajax loading of scripts (using jQuery) from CDN is't working

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).

Is it possible to submit a form to a remote script with ajax?

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.

Resources