Web Analytics Made Easy -
StatCounter Weird AJAX responseXML Return! - CodingForum

Announcement

Collapse
No announcement yet.

Weird AJAX responseXML Return!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Weird AJAX responseXML Return!

    Hi,
    I am trying to debug AJAX code. I am using PHP, Javascript and XML. I am using Firefox latest version. In PHP, I did put the code:

    header('Content-Type: text/xml');
    echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';

    I think it's the way to tell it to return whatever I echo in PHP into responseXML. And I also just echo my XML code like this:

    $string = "<title>" . $mytitle . "</title>";

    echo $string;

    But when I am using Venkman to debug my javascript, I found that the readystate is at 4 but status is never equal to 200. And the weirdest thing is that responseText shows ALL my php code(not just the thing I echo), but the responseXML is always NULL.

    Does anyone know why?

    Many thanks.
    Last edited by dealmaker; Aug 1, 2005, 10:20 PM.

  • #2
    Originally posted by dealmaker
    And the weirdest thing is that responseText shows ALL my php code(not just the thing I echo)
    Does the php page work when accessed normally? You might have a problem in mimetype settings for .php extension.
    Glenn
    vBulletin Mods That Rock!

    Comment


    • #3
      How to set mimetype for .php extension? I didn't do anything to the mimetype. I use phpedit to debug the php file alone, and it seems to be fine.

      Originally posted by glenngv
      Does the php page work when accessed normally? You might have a problem in mimetype settings for .php extension.

      Comment


      • #4
        You didn't answer my question. When you access the php page in the browser normally, does the php scripts show? If the php scripts show, then .php extension is not configured. The mimetype setting depends on the server. Some servers have it set up by default. Some you have to manually set it up.
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          I just tried, the browser shows the php code when I drag the php file to the browser!

          I am using Easyphp with Apache, so how do I set the mimetype in the apache? I would have never think of this.

          Originally posted by glenngv
          You didn't answer my question. When you access the php page in the browser normally, does the php scripts show? If the php scripts show, then .php extension is not configured. The mimetype setting depends on the server. Some servers have it set up by default. Some you have to manually set it up.

          Comment


          • #6
            Originally posted by dealmaker
            I just tried, the browser shows the php code when I drag the php file to the browser!

            I am using Easyphp with Apache, so how do I set the mimetype in the apache? I would have never think of this.
            You don't drag the file to the browser, you are running it locally. You must type the URL in the address bar, like so:

            http://localhost/path/to/page.php
            Glenn
            vBulletin Mods That Rock!

            Comment


            • #7
              ok, after I entered the url, now the browser shows me the xml that the php generates, and it's supposed to be what I see in responseXML.

              Originally posted by glenngv
              You don't drag the file to the browser, you are running it locally. You must type the URL in the address bar, like so:

              http://localhost/path/to/page.php

              Comment


              • #8
                Did you specify the URL (and not the local path) of php page in the AJAX code?
                Glenn
                vBulletin Mods That Rock!

                Comment


                • #9
                  I just put:

                  url = "my.php";
                  xmlhttp.open("GET", url, true);

                  I got the problem I stated before.

                  The weird thing is that if I put:

                  url = "http://localhost/mydir/my.php";
                  xmlhttp.open("GET", url, true);

                  there will be no response from the server after that.

                  The my.php is in the mydir directory. Everything including the html and javascript are in the mydir directory.

                  Originally posted by glenngv
                  Did you specify the URL (and not the local path) of php page in the AJAX code?

                  Comment


                  • #10
                    You must also run the page (which has the AJAX code that connects to my.php) online and not locally.
                    Glenn
                    vBulletin Mods That Rock!

                    Comment


                    • #11
                      You are the man! It works. So the whole problem was because I loaded the html file from local not online. Can't believe that it's as simple as that!

                      Thank you very much.
                      Last edited by dealmaker; Aug 2, 2005, 02:06 PM.

                      Comment

                      Working...
                      X