This is my JS:
function createRequestObject() {
var tmpXmlHttpObject;
//depending on what the browser supports, use the right way to create the XMLHttpRequest object
if (window.XMLHttpRequest)
tmpXmlHttpObject = new XMLHttpRequest(); // Mozilla, Safari would use this method ...
else if (window.ActiveXObject)
tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP"); // IE would use this method ...
return tmpXmlHttpObject;
}
//call the above function to create the XMLHttpRequest object
var http = createRequestObject();
function makeGetRequest() {
//make a connection to the server ... specifying that you intend to make a GET request
//to the server. Specifiy the page name and the URL parameters to send
http.open('get', 'FmPilot validate.php');
//assign a handler for the response
http.onreadystatechange = processResponse;
//actually send the request to the server
http.send(null);
}
function processResponse() {
//check if the response has been received from the server
if(http.readyState == 4){
//read and assign the response from the server
var response = http.responseText;
//do additional parsing of the response, if needed
//in this case simply assign the response to the contents of the <div> on the page.
document.getElementById('data').innerHTML = response;
//If the server returned an error message like a 404 error, that message would be shown within the div tag!!.
//So it may be worth doing some basic error before setting the contents of the <div>
}
}My PHP code:
<?php
require('simple_html_dom.php');
require('functions.php');
$url = 'http://website';
$username = 'user';
$password = 'pass';
$ch = curl_init();
login($ch, $username, $password, $url);
//read CSV file
$geninv = getGenInvContent();
echo '<table border="1">';
echo '<th>Invoice </th>';
echo '<th>Work Order</th>';
echo '<th>PO</th>';
echo '<th>Status</th>';
echo '<th>DNE</th>';
echo '<th>Billing Total</th>';
echo '<th>Discrepancy</th>';
echo '<th>Paperwork</th>';
echo '<th>Web Invoice?</th>';
echo '<th>Billed on?</th>';
//loop through it line-by-line
foreach($geninv as $invoice) {
$dir = 'O:\Accounting Scanning\\'. $invoice['account'] . '\\' . date('Y') . '\\' . $invoice['bulk_invoice'];
$result = findBackup($dir, $invoice['invoice']);
// collect data off the web regarding current PO
$data = getData($ch, $invoice['po_number']);
$invoiced_with = isset($data['vendorInvNum']) ? $data['vendorInvNum'] : '';
echo '<tr>';
//if paperwork is found
if ($result) {
foreach($result as $key=>$signed_workorder)
$invoice['backup'.$key] = $signed_workorder;
}
$difference = round($invoice['total'] - $data['dne'], 2);
echo '<td>'.$invoice['invoice'].'</td>';
echo '<td>'.$invoice['workorder'].'</td>';
echo '<td>'.$invoice['po_number'].'</td>';
echo '<td>'.$data['wostatus'].'</td>';
echo '<td>'.$data['dne'].'</td>';
echo '<td>'.$invoice['total'].'</td>';
echo '<td>'. $difference .'</td>';
if ($result) {
echo '<td>';
for ($i = 0; $i < count($result); $i++)
echo $invoice['backup'.$i].'</br>';
echo '</td>';
unset($result);
} else {
echo '<td>PAPERWORK NOT FOUND</td>';
}
echo '<td>'.$invoiced_with.'</td>';
if ($invoiced_with != '')
echo '<td>'.$data['invoicedate'].'</td>';
else
echo '<td></td>';
echo '</tr>';
if ($data['wostatus'] <> 'PVINV') {
$not_billable[] = array (
'invoice' => $invoice['invoice'],
'workorder' => $invoice['workorder'],
'po_number' => $invoice['po_number'],
'wostatus' => $data['wostatus'],
'dne' => $data['dne'],
'total' => $invoice['total']
);
}
}
echo '</table>';
if (isset($not_billable))
exportNB($not_billable);
curl_close($ch);
?>
My form:
<html> <head></head> <script type="text/javascript" src="ajaxrequest.js"></script> <body> <a href="http://localhost/test/FmPilot validate.php" onclick="makeGetRequest()">Check status and DNE</a><br /> <a href="http://localhost/test/FmPilot billing.php">Create Invoices</a> <div id="data"> </div> </body> </html>
What I'm trying to do is display all those PHP echoes without reloading, but it isn't working...
Looks like AJAX is working, but all it displays is this:
'; echo 'Invoice '; echo 'Work Order'; echo 'PO'; echo 'Status'; echo 'DNE'; echo 'Billing Total'; echo 'Discrepancy'; echo 'Paperwork'; echo 'Web Invoice?'; echo 'Billed on?'; //loop through it line-by-line foreach($geninv as $invoice) { $dir = 'O:\Accounting Scanning\\'. $invoice['account'] . '\\' . date('Y') . '\\' . $invoice['bulk_invoice']; $result = findBackup($dir, $invoice['invoice']); // collect data off the web regarding current PO $data = getData($ch, $invoice['po_number']); $invoiced_with = isset($data['vendorInvNum']) ? $data['vendorInvNum'] : ''; echo ''; //if paperwork is found if ($result) { foreach($result as $key=>$signed_workorder) $invoice['backup'.$key] = $signed_workorder; } $difference = round($invoice['total'] - $data['dne'], 2); echo ''.$invoice['invoice'].''; echo ''.$invoice['workorder'].''; echo ''.$invoice['po_number'].''; echo ''.$data['wostatus'].''; echo ''.$data['dne'].''; echo ''.$invoice['total'].''; echo ''. $difference .''; if ($result) { echo ''; for ($i = 0; $i < count($result); $i++) echo $invoice['backup'.$i].'
'; echo ''; unset($result); } else { echo 'PAPERWORK NOT FOUND'; } echo ''.$invoiced_with.''; if ($invoiced_with != '') echo ''.$data['invoicedate'].''; else echo ''; echo ''; if ($data['wostatus'] <> 'PVINV') { $not_billable[] = array ( 'invoice' => $invoice['invoice'], 'workorder' => $invoice['workorder'], 'po_number' => $invoice['po_number'], 'wostatus' => $data['wostatus'], 'dne' => $data['dne'], 'total' => $invoice['total'] ); } } echo ''; if (isset($not_billable)) exportNB($not_billable); curl_close($ch); ?>
it's a bit of my PHP code. Then, a few seconds later the page refreshes and I get my normal values from php.How do I get it to work the way I need?












