Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jun 2004
    Location
    Chicago
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ajax / responseText and IE question

    I'm getting a string of text back from a php file during an ajax operation. The string is something like "<p>text</p>". When I do this:


    response = request.responseText;
    myDiv.innerHTML = response;

    the innerHTML line fails out in IE but not Mozzy. Any idea why? The response alerts as a legit string of text, but IE will not deal with it - get the old "unknown runtime error" (like thats a lot of help, sheesh) at the innerHTML line in the debugger.

    I tried setting the response toString() but that did not help.
    Last edited by tdellaringa; 03-02-2006 at 06:28 PM.
    http://www.pixelmech.com/

    Get your FREE mini-mac! Totally legit - same people who do free iPods:
    http://www.FreeMiniMacs.com/?r=15890422

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Tom,
    I'm not currentl aware of any problems with IE getting responseText, so I'm just gonna try to help you debug.

    Have you tried getting any of the other response members like XML, body, etc? What have the results been.

    Can you alert anything within the callback you've defined? Can you alert the request variable?

    Sorry I can't give you the silver bullet right now, but if you're willing to test some things out, I think we can figure it out.

  • #3
    New Coder
    Join Date
    Jun 2004
    Location
    Chicago
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm willing! I probably changed my post just as you posted - reread what I wrote. The problem is the responsetext string is indeed there (I can alert it in IE) but when applied to the element.innerHTML - boom. I can't imagine why this would be an issue...

    I set my processing php file to header("Content-type: text/html") as well...
    http://www.pixelmech.com/

    Get your FREE mini-mac! Totally legit - same people who do free iPods:
    http://www.FreeMiniMacs.com/?r=15890422

  • #4
    New Coder
    Join Date
    Jun 2004
    Location
    Chicago
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the page:

    http://www.crossandthrone.com/list/member.html

    here is the php:

    PHP Code:
    <?php
    header
    ("Content-type: text/plain");
    class 
    DB {
     
      var 
    $ident;
      var 
    $sql = array('host'=>'h','user'=>'u','pass'=>'pw','db'=>'db');
     
      function 
    connect ()
      {
         
    // Connect to MySQL
         
    $this->ident mysql_connect($this->sql['host'], $this->sql['user'], $this->sql['pass']);
      
         
    // Select assigned DB
         
    if (!mysql_select_db($this->sql['db'])) {
           die(
    "Could not connect to DB");
         }
      }

      function 
    disconnect ()
      {
         
    // Close the connection
         
    if (!mysql_close($this->ident)) {
           die(
    "Could not close DB");
         }
      }

    }

    $DB = new DB();

    // Connect with info
    $DB->connect();


    // get data
    $mname $_GET['mname'];
    $mmail $_GET['mmail'];

    //echo "$mname $mmail";
    $strResponse "";

    $result mysql_query("INSERT INTO ctmembers(name, email) VALUES ('$mname', '$mmail')");
    if (!
    $result) {
       die(
    'Invalid query: ' mysql_error());
       
    $strResponse "<p>We're sorry but there is a problem with our mailing list. Please try again later.</p>";
       
    //TODO: Send myself a notification that there is a failure.
    }
    else
    {
        
    $strResponse "<p>You have successfully been added to the mailing list.</p>";
    }

    // Close connection
    $DB->disconnect();

    echo 
    $strResponse
    ?>
    http://www.pixelmech.com/

    Get your FREE mini-mac! Totally legit - same people who do free iPods:
    http://www.FreeMiniMacs.com/?r=15890422

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    IE does have some issues with trying to manipulate the dom when it's not ready for you to do so.

    Try pulling the "Working..." text out of the readystatechange == 2 || 3, that get's called constantly, when really it only needs to be called once. You could be having multiple asynchronous writes occuring to the element, which would result in IE having a coniption.

    Try that, see if it works.

  • #6
    New Coder
    Join Date
    Jun 2004
    Location
    Chicago
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, solved it - and get this one: I changed:

    $strResponse = "<p>We're sorry but there is a problem with our mailing list. Please try again later.</p>";

    to this

    $strResponse = '<p>We\'re sorry but there is a problem with our mailing list. Please try again later.</p>';

    Switched from double to single quotes in the php processing page. I don't know what this matters to IE, but somehow it does! Now that is wacky.
    http://www.pixelmech.com/

    Get your FREE mini-mac! Totally legit - same people who do free iPods:
    http://www.FreeMiniMacs.com/?r=15890422

  • #7
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Yes, indeed...

    Just for grins, if you would, try using double quotes but still escaping that single quote.

  • #8
    New Coder
    Join Date
    Jun 2004
    Location
    Chicago
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep that works too - it was the darn apostrophe! :P
    http://www.pixelmech.com/

    Get your FREE mini-mac! Totally legit - same people who do free iPods:
    http://www.FreeMiniMacs.com/?r=15890422

  • #9
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Well, hmmm, I can't remember, but aren't apostrophe and double-quote special character in html that need to be represented by the HTML entities &apos; and &quot; ?? I've never run into it, but it could be that the JScript engine in IE requires those.

    ::shrug::

    Well, at least you found it.

  • #10
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,471
    Thanks
    0
    Thanked 634 Times in 624 Posts
    Either using the entity values or escaping them will work.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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