Hi,
I am trying to create a private chat from hacking some opensource chat room.
All going well to a point.
I am trying to use some basic AJAX (noobie) to insert a field into a mysql db.
It is doing what I want it to do mysql wise but it also changes the url.
my site runs like this. There is a page called private.php with all the php in. private.php has a switch statement to call other pages (the default is home.php).
so if a user say clicks contact the link would be private.php?mode=contact.
and then in the private page the switch statement would
case "contact":
require("contact.php");
break;
so the user has searched another user and wants to chat.
the url at the moment is private.php?mode=full_profile&id=101
in the full_profile.php page I have the ajax in the head and a submit form to call the ajax function.
here is the ajax code
<script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
var ajaxRequest;
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('ajaxDiv');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}
var c_id = document.getElementById('c_id').value;
var p_id = document.getElementById('p_id').value;
var queryString = "?c_id=" + c_id + "&p_id=" + p_id;
ajaxRequest.open("POST", "insert.php" + queryString, true);
ajaxRequest.send(null);
}
//-->
</script>
and the submit form
form name='myForm'>
<input type='hidden' id='c_id' value="33" /> <br />
<input type='hidden' id='p_id' value="43" />
Chat Now<input type="image" onclick='ajaxFunction();' src="../images/chat.png" >
</form>
<div id='ajaxDiv'></div>
the ajax calls insert.php
$c_id = $_REQUEST['c_id'];
$p_id = $_REQUEST['p_id'];
mysql_query("INSERT INTO chat (target,name) VALUES ('$p_id','$c_id')");
now the mysql query runs fine. the problem I have is that when I click the submit the url changes to private.php?x=18&y=28 . (the x and y vales are different everytime I click the submit).
can anyone tell me where the x and y values are coming from and also why the ajax function is changing the url as the whole point of using ajax is to avoid that
many thanks in advance