Tip Details Add a Related Tip

Rate as: Positive Negative

jQuery ajax responseText empty

I ran into a problem using the $.ajax command synchronously in jQuery. I'd make my call. But when I get the XMLHttpRequest object back, the responseText was empty. My call looked like this.

var response = $.ajax({
	url:		'/formCheck',
	type:		'POST',
	cache:		false,
	asynch:		false,
	data:		postObj,
});

console.log(response.responseText);

After wasting 2 hours trying to figure out what was wrong, I noticed that I had a spelling error in my request object. The asynch should be async (no h). I fixed this typo and everything started working as it should.

So if you can't get the jQuery ajax command to work synchronously and return the responseText, check your calling object. The JSON format is very convenient, but if you make a mistake in the naming of a parameter it just gets ignored and you're left scratching your head.
Rating: 100% positive, 4 total Votes
Categories: javascript jQuery programming
Added: on Mar 27, 2009 at 8:26 am
Added By: an anonymous user
Searches: jquery javascript programming responsetext ajax

Comments on this Tip

Add a Comment
Thanks for your tip. It's working great.
– Added by an anonymous user on Jun 22, 2009 at 3:12 am
I was facing response text character limit problem. I had a somewhat large amount of data in proposed responseText to get and everything was working well while testing. But it stopped to show the data at once and just loader would show spinning. I debugged a lot to find out a reason and finally got that it did not support more than 8442 characters in "html" response type. Here is the code i was trying to get the data:

var url = "load_pocket_fabrics.php?filter=" + $("#eleID").val();
$.ajax({
url: url,
type: 'GET',
dataType: 'html',
timeout: 1000,
async:false,
before: $("#contentID").prev("div.loader").show(),
success: function(msg){
alert(msg);return;
}
});


Searching for a solution i end up on this post and tried async=false in the code and it worked!

Thanks for this wonderful post!
– Added by an anonymous user on Aug 25, 2009 at 9:58 am
Your Comment:
(how to format)
Rate This Tip:

Verify Humanity:
Sorry, we know it's annoying, but please enter the characters shown in the image to the left so that we know you're an actual person and not an evil spammer. Thanks.
       

Related Tips

reading select element values in javascript in IE7

100% positive, 0 comments
– Tip added by an anonymous user on Jul 17, 2009 at 1:28 pm

animating elements with jQuery

0% positive, 0 comments
– Tip added by an anonymous user on Aug 04, 2008 at 1:46 pm

Detecting if a variable exists in Javascript

100% positive, 2 comments - last added on Oct 21, 2009 at 2:29 pm
– Tip added by an anonymous user on Jul 22, 2008 at 8:31 am

Telling when an iframe is done loading

85% positive, 3 comments - last added on May 16, 2009 at 7:48 am
– Tip added by an anonymous user on Apr 18, 2008 at 8:05 am

Length of associative arrays in Javascript

100% positive, 0 comments
– Tip added by an anonymous user on Nov 04, 2008 at 10:13 am

Matching any character in a javascript regular expression

100% positive, 2 comments - last added on Oct 08, 2009 at 2:33 am
– Tip added by an anonymous user on Aug 18, 2008 at 9:06 am

Trimming whitespace in Javascript

Categories: javascript programming
100% positive, 0 comments
– Tip added by an anonymous user on Sep 13, 2007 at 1:54 pm

Efficient building of large strings in Javascript

100% positive, 0 comments
– Tip added by an anonymous user on Aug 08, 2007 at 12:52 pm

Unable to click in text input boxes on Internet Explorer

100% positive, 2 comments - last added on Aug 07, 2009 at 4:57 pm
– Tip added by Marcos84 on Dec 09, 2008 at 10:49 am

Optional parameters in javascript functions

100% positive, 0 comments
– Tip added by an anonymous user on Jul 30, 2008 at 10:44 am

Using optional parameter in javascript

Categories: javascript programming
100% positive, 0 comments
– Tip added by an anonymous user on Jul 17, 2008 at 7:49 am

Javascript Error: unterminated regular expression literal

50% positive, 0 comments
– Tip added by marty on Jun 26, 2008 at 1:20 pm

Javascript variable naming

100% positive, 1 comment - last added on Jul 22, 2008 at 8:33 am
– Tip added by an anonymous user on Sep 30, 2007 at 7:28 am

Don't include a "length" attribute in a JSON Object

100% positive, 0 comments
– Tip added by an anonymous user on Apr 10, 2009 at 4:51 pm

Checking for undefined variables in Javascript

100% positive, 1 comment - last added on Jul 14, 2009 at 5:13 pm
– Tip added by an anonymous user on Jan 14, 2009 at 9:47 am

Debugging Javascript

100% positive, 0 comments
– Tip added by an anonymous user on Sep 12, 2008 at 2:35 pm

compressing javascript

100% positive, 0 comments
– Tip added by an anonymous user on Jun 12, 2008 at 3:02 pm

Code for creating Javascript CSS charts

100% positive, 0 comments
– Tip added by an anonymous user on Aug 21, 2007 at 12:23 pm

attaching events to nodes in Javascript

no ratings, 0 comments
– Tip added by an anonymous user on Aug 18, 2008 at 11:23 am

Javascript: How to Create a Random Number

0% positive, 0 comments
– Tip added by Walkere on Feb 23, 2008 at 9:49 pm