SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help I am working through Ajax Web Application book and an if statement does not work

    I am trying just to work through the second chapter of Ajax Web Applications and I keep getting that the request failed, but I put an alert in just prior to the if and it shows that the value of the str is ok so it should work. I think there is a type mismatch

    appmonitor1.js:

    var start = 0;
    var ajax = new Ajax();


    var doPoll = function(){
    start = new Date();
    start = start.getTime();
    ajax.doGet('/fakeserver.php?start=' + start, showPoll);
    }

    window.onload = doPoll;

    var showPoll = function(str) {
    var pollResult = '';
    var diff = 0;
    var end = new Date();
    alert(str);
    if(str == 'ok') {
    end = end.getTime();
    diff = (end - start) / 1000;
    pollResult = 'Server response time: ' + diff + ' seconds';
    }
    else {
    pollResult = 'Request failed.';
    }
    printResult(pollResult);
    var pollHand = setTimeout(doPoll, 15000);
    }

    function printResult(str) {
    var pollDiv = document.getElementById('pollDiv');
    if (pollDiv.firstChild) {
    pollDiv.removeChild(pollDiv.firstChild);
    }
    pollDiv.appendChild(document.createTextNode(str));
    }

    fakeserver.php:

    <?php
    header('Content-Type: text/plain');
    sleep(rand(3,12));
    print 'ok';
    ?>

  2. #2
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have solved my Problem.
    in the fakeserver.php after the closing tag(?>) I have hit enter which added a carrage return and line feed to the information that was being sent back to the calling script...ops


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
  •