jQuery ajax post is sending request using get method on ipad chrome - javascript

When this code runs on chrome on ipad, it ignores the type "POST" and sends the ajax request using the get method. Is it a compatibility issue? Seems like chrome doesnt support post ajax requests?
$.ajax({
type: "POST",
url: "/ajaxCall",
data: sentData,
success: success,
dataType: "text",
error: function (jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
});

I was testing the page on k-tunnnel/v-tunnel. I found out that the problem is becaouse of these sites. Without tunneling, my calls reaches the server properly.

Related

Jquery ajax call for generate authorization code

As part of my requirement, I would like to generate authorization code by calling O365 url from jquery ajax call. I am calling below script from document ready()
$.ajax({
type: 'GET',
dataType: 'jsonp',
async: false,
url: 'https://login.microsoftonline.com/{{tenant id}}/oauth2/authorize?client_id={{client id}}&response_type=code&redirect_uri=https://myurl.com/createpage/&response_mode=query&resource={{resource}}&state=9128',
crossDomain: true,
success: function(jsonData) {
alert(jsonData);
},
error: function(request, textStatus, errorThrown) {
console.log(errorThrown);
},
cache: false
});
But it is getting following error.
Jquery ajax error
Request you to help on resolving the issue.
You should check the content of the response in the tab network (in your dev tools).
I guess the response is not a valid json, so the parsing failed (your specified the jsonp type in your ajax call)

Loading image in ajax call is not working in chrome

I have a html page where i want to display processing with loading image between ajax call for save and its success.
And that page i put in dynamics crm as webresourse.
Problem is that Loading works fine in mozilafirefox but not working in
chrome.
Script:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
Other Code:
<img src="sm_loading.gif" id="loading" style="display:none" />
<input class="custom-btn" id="btnsave" value="Save" onclick="SaveData();" type="button">
function SaveData() {
$('#loading').show();
var stocktrack = {};
stocktrack.sm_Description = descval;
var jsonPO = window.JSON.stringify(stocktrack);
var oDataUri = serverUrl + "/XRMServices/2011/OrganizationData.svc/sm_stocktrackingSet";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: oDataUri,
data: jsonPO,
async: false,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
debugger;
$('#loading').hide();
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
Please suggest if any solution is there.
I ran your code in Firefox and it worked. I also ran in Chrome and got nothing, just as you said. However, by turning on the debugger in Chrome, using F12, I got the following error.
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
To fix this set the async flag inside your ajax call equal to true.
If you want to keep your user from pressing things during your async call, which is perfectly understandable, I suggest you use a transparent blocking layer.
I Got my answer.
With the use of setTimeout(function(){..our code..},10); I am able to display loading in chrome with async:false.
Reference Link:
https://www.experts-exchange.com/questions/25187194/jQuery-async-false-with-beforeSend.html
Loading Panel only work with async:True,
Other wise it will only work on firefox and most other browsers does not show loading panel.
But with asynchronous false all the code below other than success and error(call back functions) will be execute.

Ajax jquery call to GET application/x-javascript

How do I get content of "application/x-javascript" using jquery Ajax call?
As it keep getting me null content.
What I am trying to use for now:
$.ajax({
dataType: "json",
contentType: "application/x-javascript;charset=utf-8",
url:the_url,
async:false,
success:function(r){
console.log("el result" + r) ;
response = r;
}
});
This:
dataType: "json",
tells jQuery to ignore what the server claims it is sending back and to process the result as JSON. JavaScript isn't JSON, so this breaks it.
Remove that line.
Then you should get the data in the success function.
Asides:
This:
contentType: "application/x-javascript;charset=utf-8",
claims you are sending JavaScript. You aren't making a POST request, so you aren't sending anything. Remove it.
Even if you were sending JavaScript to the server, the application/javascript MIME type hasn't been experimental since 2006, so it shouldn't have the x- prefix on it.
async:false, is a terrible idea. It locks up the JS event loop waiting for the response. You shouldn't use it.
response = r;: assigning data to globals is usually a terrible idea. Process the data in the success event handler instead.
Try this out :
$.ajax({
url: 'my/url',
type: 'GET',
data: 'test=mytest&test2=mytest2',
success: function (data) {
console.log(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
And read the documentation, to see what each parameter is made for :
http://api.jquery.com/jquery.ajax/

JQuery Ajax Error on Internet Explorer

I'm making an Ajax Request, it's working in all browser, but in Internet Explorer It's not working. I need that works for internet explorer 9 +
That's the request:
function loadYoutubeVideos(youtubeUrl){
var url = 'youtubeUrl';
$.ajax({
type: 'GET',
dataType: "json",
url: url,
success: function (responseData, textStatus, jqXHR) {
objYoutubeVideos = responseData;
//more functions, blablabla
},
error: function (responseData, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
//error functions
}
});
}
I'm making the some code for load a Facebook Page Content. What do I do?
Have you tried to using jsonp format?
The json format has a issue when use over cross-domain (different domain).
So, you need to use jsonp instead of json, jsonp using javascript callback for solve the cross-domain issue.
more: http://www.sitepoint.com/jsonp-examples/
You don't need create pipe for api request.
Youtube support jsonp format using &callback= parameter.

jQuery.ajax() sends POST requests as GET in a Chrome extension

I'm building a small Chrome extension that must send messages through a POST http request to a server in my company network, and I'm using jQuery 1.4.1 to speed up the development of the javascript part.
I have this code to send the request:
function send() {
$.ajax({
url: "http://mycompany.com/update",
method: "POST",
data: {status: "sometest", in_reply_to_status_id: "anId"},
success: function(data, textStatus) {
console.log("success");
console.log(data);
console.log(textStatus);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log("error");
console.log(XMLHttpRequest);
console.log(textStatus);
console.log(errorThrown);
},
complete: function(XMLHttpRequest, textStatus) {
console.log("complete");
}
});
}
The request done this way fails, in the Chrome log I see that the server responds with a http status 400 and with the text "This methods requires POST".
If I change to code above with this:
function send() {
$.post("http://sunshine.emerasoft.com/statusnet/api/statuses/update.xml", {status: "sometext", in_reply_to_status_id: "anId"}, function(data) {
console.log(data)
});
}
everything works fine, the http status is 200 and server side I can see that the data I sent is correctly saved.
I need to use the full $.ajax() method because I need to do some work in case of success or failure, and some other when the request is complete, so $.post() is not enough.
Am I doing something wrong calling $.ajax(), or there is an issue of some kind, maybe because I am in the xontext of a Chrome extension?
Thanks
I believe the $.ajax() function takes a 'type' option, not a 'method' option.
The default type is GET.

Categories

Resources