|
|
楼主 |
发表于 2012-6-12 08:22:45
|
显示全部楼层
本帖最后由 demo 于 2012-6-13 00:24 编辑
making an IRC type thing to run in a browser window. Ethe way I submit the new message:
send values via AJAX
set action="#" in your form tag this way it wont navigate away...
another way is to use a hidden iframe.
do something like this:
Code:
// JavaScript/AJAX
function ajax_setup()
{
var xmlhttp;
var contents = document.getElementById("some_id").value;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState == 4)
{
document.getElementById("text").innerHTML += xmlhttp.responseText;
}
}
xmlhttp.open("GET", "your_php_file.php?your_get_id=" + contents, true);
xmlhttp.send();
}
Then instead of calling PHP file from the button, call this JavaScript function instead, which calls the PHP file within it. In your PHP file, you would simply echo the return value of the database retrieval somewhere in the source, which would then be handled by the onreadystatechange function and the value would be placed in a text-based element like a <div> or <input type="text" />.
to use the function as suggested, you need to use that button also and use onclick event handler to call the ajax javascript function
|
|