$.post doesn't work in Internet Explorer with data

Hey Sitepoint, I’m running into a really strange AJAX problem which I haven’t encountered yet in Internet Explorer.

The following code works:


$.post("home.php", function(data){
		
    console.log('success');
			
});

However this doesn’t (in IE):


$.post("home.php",{foo: 'bar'}, function(data){
		
    console.log('success');
			
});

I must be missing something here…

Try switching the data and url, so that the url comes first as according to the .post() documentation.

Hmm? But the url comes first in $.post(“home.php”,{foo: ‘bar’}, function(data){
I’m going to dumb my code down even more and create a testcase because I have some other AJAX calls that work fine in IE.

Internet Explorer doesn’t know anything about the console. Have you factored that in to things?

Here’s a simple test.



<html>
<head>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script>
$.post("test.php",{foo: 'bar'}, function(data){
    console.log('success');
});
</script>
</body>
</html>

My full test code is now:


$('#search-form select').change(function(){
	
	if($('#current-page').val() == "home")
		reload_activities();
			
});

function reload_activities(){
		
	console.log('starting');

	$.post("home.php",{foo: 'bar'}, function(data){
		console.log('success');
	}); 
		
}

I get “starting” in console but not “success”.

And when I remove {foo: ‘bar’}, it works.

I’m not sure what you mean by Internet Explorer doesn’t know anything about the console or how this would affect me here.

Hmmmmmmm. The select I was testing with is one of four, and the other three work fine (use the same event handler). Also after using one of the other selects this one starts working as well.

This can either be because the Javascript gets loaded again or because the variables get changed, I think there’s something weird in my other code.

EDIT: NVM, it’s not the other selectboxes that make it work, it’s my inputfield that has a different event handler. I’m going to look around some more and maybe post here if I still can’t find it.

EDIT:
It seems to have something to do with the plugin I’m using for my dropdowns. I’m going to try and figure out what the problem is but it must be conflicting somewhere because when I turn that plugin off it works like a charm.

I’m not sure what you mean by Internet Explorer doesn’t know anything about the console or how this would affect me here.

Just on the console.log support, Internet Explorer 9 allows console.log() when the developer tools are open in a vanilla install, even though it’s considered an addon. All other versions of IE will throw an “undefined object” error unless you fudge support for it (by deploying code that adds an object called console).

‘console’ is not a native javascript object, if you use it without checking if it exists, or targeting a particular browser that supports it you will have issues. Great for debugging, just remember to remove it when you are done coding.