I have the following AJAX function:
function ajaxDesignerBrandInfo()
{
var D = wrapFormValues('#designer-brand-form');
var recursiveEncoded = $.param(D);
/*
$.post("/api/designer_brand/", { data : recursiveEncoded }, function(data)
{
var results = $.parseJSON(data);
window.location = "/register/designer-product/";
});*/
$.ajax( { type: "POST",
url: "/api/designer_brand/",
data : { data : recursiveEncoded },
success: function(data) {
console.log(data);
setTimeout(function() {
window.location = "/register/designer-product/";
},0);
},
error: function (xhr, ajaxOptions, thrownError ){
alert(xhr.status);
alert(thrownError); }
});
return false;
}
And the corresponding form
<form id="designer-brand-form" name="form" method="post" action="" onSubmit="ajaxDesignerBrandInfo(); return false;">
....
</form>
The submission works great on Chrome, Safari and FireFox, moving me to
/register/designer-product/
Correctly, but in IE9, the submissions seems to
Never make it to the server
clear the form and redirect back to the current page i am on (in which this form exists).
I can confirm via FireFox there are no javascript errors causing this to fail. And sometimes it actually works, but I cannot seem to always reproduce this error in the same way
Someone Please explain WTF is going on?
Thanks
I believe your issue is that IE is silently throwing a Javascript error. Just because Firefox doesn't throw a JS error one doesn't mean that IE doesn't. Check for JS errors in IE (see this link or this one). Find the error and you'll find the solution.
Also, try Fiddler, which is a standalone Windows tool that acts as a proxy server and will tell you EXACTLY what your AJAX traffic looks like.
Your specific problem may be the console.log call. That is a Firebug thing (that Chrome supports). IE does not, I think, unless you take steps to add it. See: What happened to console.log in IE8?
Related
I develop phonegap app for symbian (cordova for symbian I'm get from here)
After 3-5 seconds when my app begin execute ajax request, I get error:
Maybe someone faced with this issue?
Update1:
I make cross-domain ajax request with jquery mobile 1.8.1
$.ajax({
type: 'GET',
url: "http://example.org/some/path",
dataType: "json",
mimeType: "application/json",
headers: { "TOKEN": "%SOME_TOKEN%" }
}).done(function (data) {
// success processing
}).fail(function (xhr, textStatus) {
// fail processing
});
It could be as simple as the fact that you're missing " from the url line of your AJAX creation, but I suspect it isn't. I'm guessing that's a copying typo. This error message means your getting an uncaught exception which is bringing your app down.
Other people have reported JQuery for mobile being buggy, and having problems with certain HTTP Response statuses. I suggest bypassing it altogether, and making your own AJAX request, as a workaround (plenty of examples on the internet; I would alert the response status just so you can see what you're getting).. If that works, you can investigate whether other version of JQuery suffer from the same bugs.
Example AJAX without JQuery:
<script type="text/javascript">
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4)
{
// do stuff with xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
</script>
KERN-EXEC 3 is due to referencing a bad pointer or running out of stack space. It's probably the latter but it's impossible to say. Is there any way you can provide a call-stack?
what's weird about my error is that it ONLY occurs in the firefox extension I have linked to at the bottom of this post. I cannot reproduce this error in any other setting.
I have this ajax request
$.ajax({
type: "GET",
dataType: "jsonp",
url: url,
jsonpCallback: "JSONCallback",
data: {title:$("#txtTitle").val(), url:taburl},
success: function(data, textStatus) {
if(data.code > 0)
{
$("#icon").removeClass().addClass('accept');
}
else
{
$("#icon").removeClass().addClass('error');
if(data.code == '-1')
alert('kunne ikke finde din ønskeseddel på e-ønsker.dk - besøg e-ønsker.dk, og prøv derefter igen');
}
},
error: function(xhr, textStatus, errorThrown) {
alert("XMLHttpRequest="+xhr.responseText+"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown);
$("#icon").removeClass().addClass('error');
}
});
server returns
JSONCallback({"code":405});
headers are application/json
so why am I getting a parseError saying JSONCallback was not called? I thought jQuery was supposed to handle that for me?
the code is from http://builder.addons.mozilla.org/addon/1022928/latest and the file in question is data/panel.js
The problem is with window. The easiest way to fix this will be to edit the jQuery code (I know, I hate doing this too) to use unsafeWindow rather than window.
have you tried to enable the"Cross-Origin Resource Sharing"
using :
jQuery.support.cors = true;
i had the same issue with firefox a while ago and using that line before making my ajax call fixed it for me.
i coulnd get your fizzle to work for some reason :) good luck
This isn't really an answer, but why are you using jsonp? Code running in the context of a Firefox extension isn't subject to the cross origin restriction.
My understanding of jsonp is that a script tag is added to the document using the server's response so that your callback is executed. In a Firefox extension "document" is the XUL UI not the regular page's document. I'm not sure that adding a script element to XUL will cause the browser to execute that script.
Hope this helps!
This chunk of code works fine on FireFox but in IE it gives runtime error when I try to dump the contents from response returned from AJAX response.I am using mootools to make Ajax call.
//on dom ready...
window.addEvent('domready', function() {
/* ajax alert */ <br/>
$('ajax-alert').addEvent('click', function(event) {
//prevent the page from changing
event.stop();
//make the ajax call
var req = new Request({
method: 'get',
url: $('ajax-alert').get('href'),
data: { 'do' : '1' },
onRequest: function() { alert('Request made. Please wait...'); },
onComplete: function(response) {
alert(response);// Getting response and able to see that in alert
/*line underneath fives runtime error in IE , works fine in FireFox */
document.getElementById('myDiv').innerHTML = response;
//this line gives run time error on IE
}
}).send();
});
This is likely to happen when the returned response is not a valid X/HTML. I suggest you validate the page with the response returned in it. As Dimitar Christoff has mentioned, watch out for inline elements containing block elements.
I'm using jQuery 1.4.2 and am trying to perform a simple AJAX request. The target URL returns a JSON string (I validated it with jslint). The request works in Firefox and Chrome, but doesn't want to work in IE8, and I can't determine why. Here is the call:
jQuery.ajax({
url: 'http://' + domain + '/' + 'helper/echo/',
dataType: 'json',
success: function(data) {
alert(data);
},
beforeSend: function(request, settings) {
alert('Beginning ' + settings.dataType + ' request: ' + settings.url);
},
complete: function(request, status) {
alert('Request complete: ' + status);
},
error: function(request, status, error) {
alert(error);
}
});
IE will execute the beforeSend callback and the error callback. The error callback alerts with the message:
Error: This method cannot be called until the open method has been called.
My response header returns with Content-Type: text/javascript; charset=UTF-8.
What is going on with IE? I'm running the server on localhost, making a request from http://localhost:8080/psx to http://localhost:8080/helper. Maybe IE is blocking this request? I have tried installing Fiddler to analyze request traffic but it won't run on my machine because it's rather locked down. Firebug lets me, but everything seems good there.
Thanks for the help!!!
Alright, here's the fix! The request was using window.XMLHttpRequest(), which isn't working properly in IE8 for some reason. jQuery is not failing back to window.ActiveXObject("Microsoft.XMLHTTP") as it should.
Add this to your script somewhere before your AJAX call (only verified in IE8, not other IE's):
jQuery.ajaxSetup({
xhr: function() {
//return new window.XMLHttpRequest();
try{
if(window.ActiveXObject)
return new window.ActiveXObject("Microsoft.XMLHTTP");
} catch(e) { }
return new window.XMLHttpRequest();
}
});
Here's how I came to the solution:
Updated to jQuery 1.4.4 in case the issue was a bug that had been fixed.
Stepped through Firebug debugger and DevTools debugger until the results seemed to be drastically different.
On line 5899, the ajax() function creates the XmlHttpRequest object with the xhr() function. In Firefox, it was returning good data. In IE, this was returning with all fields being Error: This method cannot be called until the open method has been called.
I analyzed this function on line 5749, return new window.XMLHttpRequest();
I googled and came across this page that has the same problem and suggested the solution that works for me.
Official jQuery ticket:
I am using jQuery ajax version 1.4.1 in my MVC application (though the issue I am discussing was same with the old jQuery version 3.2.1) as well, to check during customer registration if the username is already registered. As the user clicks on the "Check Availibility" button, I am showing a busy image in place of the check button (actually hiding the check button and showing the image) while checking the availibility on the server and then displaying a message. It is a Sync call (async: false) and I used beforeSend: and complete: to show and hide the busy image and the check button. This thing is working well on Firefox but in IE 8 and Chrome, neither the busy image appear nor the check button hides rather the check button remained pressed as the whole thing has hanged. The available and not available messages appear correctly though. Below is the code:
HTML in a User Control (ascx):
<div id="available">This Username is Available</div>
div id="not_available">This Username is not available</div>
<input id="txtUsername" name="txtUsername" type="text" size="50" />
<button id="check" name="check" type="button">Check Availability</button>
<img id="busy" src="/Content/Images/busy.gif" />
On the top of this user control, I am linking an external javascript file that has the following code:
$(document).ready(function() {
$('img#busy').hide();
$('div#available').hide();
$('div#not_available').hide();
$("button#check").click(function() {
var available = checkUsername($("input#txtUsername").val());
if (available == "1") {
$("div#available").show();
$("div#not_available").hide();
}
else {
$("div#available").hide();
$("div#not_available").show();
}
});
});
function checkUsername(username) {
$.ajax({
type: "POST",
url: "/SomeController/SomeAction",
data: { "id": username },
timeout: 3000,
async: false,
beforeSend: function() {
$("button#check").hide();
$("img#busy").show();
},
complete: function() {
$("button#check").show();
$("img#busy").hide();
},
cache: false,
success: function(result) {
return result;
},
error: function(error) {
$("img#busy").hide();
$("button#check").show();
alert("Some problems have occured. Please try again later: " + error);
}
});
}
I found the answer to my question. It was actually the sync call (async = false) which was making IE mad. I removed that and adjusted the code and everything is working fine now.
Point to Note: async=false is deprecated as of jQuery 1.5
Should be using complete() callback instead.