Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX call to server make XML periodically
    primarykey
    data
    text
    <p>I want to make an AJAX call to the server periodically, the server script(PHP) should make a new XML file. The XML file is then read by another javascript function and displayed on webpage. How do I accomplish this? Heres the Jquery code I have:</p> <pre><code>setInterval( function(){ $.Ajax({url: 'register.php'});}, 5000 ); </code></pre> <p>the PHP code that is being requested:</p> <pre><code>session_start(); $user = $_SESSION['username']; $uID = $_SESSION['UserID']; $host="127.0.0.1:3306"; $db_name='wf_db'; $tbl_name="tasks"; $connect = new mysqli("$host","root"," ","$db_name")or die('Can\'t connect to database!'); $sql = "SELECT * FROM $tbl_name WHERE UserID='$uID' and Task_Completed='0'"; $query_data = mysqli_query($connect,$sql)or die('Couldnt get data'); $row = mysqli_num_rows($query_data); chmod("result".$uID.".xml", 0755); if($row != 0){ $file = fopen("result".$uID.".xml",'w')or die("Cannot Open File"); $_xml = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\" ?&gt;\r\n"; $_xml .="&lt;tasks&gt;\r\n"; while ($result = mysqli_fetch_array($query_data)) { if ($result["TaskID"]) { $_xml .="\t&lt;task&gt;\r\n"; $_xml .="\t\t&lt;AssignDate&gt;" . $result["Assign_Date"] . "&lt;/AssignDate&gt;\r\n"; $_xml .="\t\t&lt;TaskID&gt;" . $result["TaskID"] . "&lt;/TaskID&gt;\r\n"; $_xml .="\t\t&lt;TaskSubject&gt;" . $result["Task_Subject"] . "&lt;/TaskSubject&gt;\r\n"; $_xml .="\t\t&lt;Notes&gt;" . $result["Notes"] . "&lt;/Notes&gt;\r\n"; $_xml .="\t&lt;/task&gt;\r\n"; } else { $_xml .="\t&lt;task title=\"Nothing Returned\"&gt;\r\n"; $_xml .="\t\t&lt;AssignDate&gt;none&lt;/Assign_Date&gt;\r\n"; $_xml .="\t\t&lt;TaskID&gt;none&lt;/TaskID&gt;\r\n"; $_xml .="\t\t&lt;TaskSubject&gt;none&lt;/TaskSubject&gt;\r\n"; $_xml .="\t\t&lt;Notes&gt;none&lt;/Notes&gt;\r\n"; $_xml .="\t&lt;/task&gt;\r\n"; } } $_xml .="&lt;/tasks&gt;"; fwrite($file, $_xml); fclose($file); } else { echo 'Oops something went wrong!'; } </code></pre> <p>This is what I have so far, what am i missing? I am new to PHP and AJAX so there might be errors in the code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload