I get a warning from my php file on the server not sure what is wrong. I am making an ajax call from my javascript function to the server and it just does not receive any response in xmlhttp.readyState == 4 && xmlhttp.status == 200
.
I tried to make the same call to the php file/mysql database located on my local computer it works but it would not work for a remote host. Also, i have a similar php file on the server with just the select clause different and it works there not sure what is wrong here ?
.
Warning: Cannot modify header information - headers already sent by (output started at /home2/marshell/public_html/cfv/getuserpostbybusnumber.php:2) in /home2/marshell/public_html/cfv/getuserpostbybusnumber.php on line 4
.
<?php
ob_start();
header("Access-Control-Allow-Origin: *");
$q = intval($_GET['q']);
$con=mysqli_connect("localhost","ma","Ad","mars","3306");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM cfv_viewbusupdate WHERE BusNumber = ".$q." ORDER BY DatePosted DESC");
while($row = mysqli_fetch_array($result))
{
echo "<P>";
echo "<B><font color=\"3300CC\">#" . $row['DatePosted'] . "</font></B> --";
echo "" . $row['username'] . " posted </br>";
echo "<B>Bus Number . </B>";
echo "<font color=\"CC0033\">" . $row['BusNumber'] . "</font></br><B> Going towards </B>";
echo "<font color=\"CC0033\">" . $row['Direction'] . "</font></br> <B>Stop Name: </B>";
echo "<font color=\"CC0033\">" . $row['StopNames'] ."</font></br><B> Time </B><font color=\"CC0033\">".$row['time']." </font></br><B> Status </B>";
echo "<font color=\"CC0033\">" . $row['Status'] . "</font> ";
echo "</br> <B> Comment's </B>: <font color=\"CC0033\">" . $row['comments'] . "</font>";
echo "</P>";
echo "<hr> ";
}
mysqli_close($con);
?>
.
function updateUserPost(str) {
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState < 4) {
showModal();
}
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
// $('#select-choice-direction-foruserpost').html(xmlhttp.responseText).selectmenu( "refresh");
hideModal();
document.getElementById("result").innerHTML = xmlhttp.responseText;
//alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET", "http://www.xyz.uni.me/cfv/getuserpostbybusnumber.php?q="+str, true);
xmlhttp.send();
}