Results 1 to 8 of 8

Thread: httprequest problem

  1. #1
    Join Date
    Dec 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default httprequest problem

    Hi,
    I have started to use Ajax.I have downloaded the following code but the status property of the httprequest is 0 and I donot know how to fix it.The server is apache Http server and having it running or not, seem does not make any difference.
    <script type="text/javascript" language="javascript">

    var http_request = false;

    function makeRequest(url) {

    http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
    http_request.overrideMimeType('text/xml');
    // See note below about this line
    }
    } else if (window.ActiveXObject) { // IE
    try {
    http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
    }
    }

    if (!http_request) {
    alert('Giving up Cannot create an XMLHTTP instance');
    return false;
    }
    http_request.onreadystatechange = alertContents;
    http_request.open('GET', url, true);
    http_request.send(null);

    }

    function alertContents() {


    if (http_request.readyState == 4) {

    if (http_request.status == 200) {
    alert(http_request.responseText);
    } else {
    alert('There was a problem with the request.'+http_request.statusText);
    }
    }

    }
    </script>
    <span
    style="cursor: pointer; text-decoration: underline"
    onclick="makeRequest('test.html')">
    <p>
    Make a request
    </span>

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I daresay you're testing that page locally (/home/user/ajax.html or C:\Documents and Settings\user\ajax.html) rather than via the webserver (http://127.0.0.1/ajax.html).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Dec 2005
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    why are you trying to run it on apache if you are not using mysqp or php. just test it normally.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    jstgermain: The HTTP Request object, strangely, needs a server to make HTTP requests to. Apparently, on Windows, a local file is treated as a resource on a webserver. This idiosyncratic and potentially dangerous behaviour allows the XMLHttpRequest object to be used without a webserver. However, it cannot be relied upon to act the same way as it would had it a real webserver to make requests to.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Dec 2005
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    jstgermain: The HTTP Request object, strangely, needs a server to make HTTP requests to. Apparently, on Windows, a local file is treated as a resource on a webserver. This idiosyncratic and potentially dangerous behaviour allows the XMLHttpRequest object to be used without a webserver. However, it cannot be relied upon to act the same way as it would had it a real webserver to make requests to.
    thanks for that insight, i was not aware that javascript needed to be run on a server for certain scripts. i thought all javascript could be run normally on the computer.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Generally speaking, it can. AJAX is the exception to the rule.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jan 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I tried an AJAX example on my local machine (Powerbook running 10.4.3, Apache, MySQL, PHP) and couldn't get it to work either. I uploaded it to my hosting space and it didn't work there either. You can see the code at my Google groups post. I appreciate any help you guys can offer.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Could you give us the URL of the uploaded page?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •