SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $.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:

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

    However this doesn't (in IE):

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

    I must be missing something here...

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Kokos View Post
    I must be missing something here...
    Try switching the data and url, so that the url comes first as according to the .post() documentation.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Kokos View Post
    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.

    Code javascript:
     
    <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>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My full test code is now:

    Code JavaScript:
    $('#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.

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  6. #6
    SitePoint Addict Kokos's Avatar
    Join Date
    Nov 2005
    Location
    The Netherlands
    Posts
    205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Taking over the web one pixel at a time.
    Currently working @ CodeCreators

  7. #7
    SitePoint Enthusiast Anthony.Barnes's Avatar
    Join Date
    Aug 2011
    Location
    Canberra, Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •