30-01-2007, 20:00
|
|
|
חבר מתאריך: 17.05.05
הודעות: 7,321
|
|
זהו שזה לא פונקציה גלובאלית ואני לא רוצה שזו תהיה אחת כזו.
זה הקוד של ה"מחלקה" ב-JS (תעתיקו ל-Notepad את הקוד, זה יותר נוח לקרוא ככה):
קוד:
function xmlhttp()
{
this.xmlHttp=null;
this.useHeader = '';
}
xmlhttp.prototype.GetXmlHttpObject = function()
{
try
{
this.xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); /* For IE v6+ */
}
catch(e)
{
try
{
this.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); /* For IE v5.5+ */
}
catch(e) { }
}
if (this.xmlHttp==null)
{
this.xmlHttp=new XMLHttpRequest(); /* For the newer versions of Firefox, Mozilla, Safari, Netscape and Opera */
}
return this.xmlHttp;
}
xmlhttp.prototype.stat = function()
{
if ((this.xmlHttp.readyState==4 || this.xmlHttp.readyState=="complete") && this.xmlHttp.status==200 )
return TRUE;
return FALSE;
}
xmlhttp.prototype.go = function(URL, toDo, meth)
{
WebBaseURL = '';
var method = (meth == 'post' ? 'POST' : 'GET');
var url = URL ? WebBaseURL+URL : WebBaseURL;
this.xmlHttp.onreadystatechange = toDo;
this.xmlHttp.open(method,url,true);
this.xmlHttp.send(null);
}
xmlhttp.prototype.reply = function()
{
return this.xmlHttp.responseText;
}
זה הקוד HTML שמנסה להפעיל את המחלקה והפונקציות שבה ולמעשה לעשות xmlHttp request:
קוד:
<div id='BLAM' style='background-color:black;color:white;'>vcf</div>
<script src="scripts/xmlHTTPRequest.js" type='text/javascript'></script>
var do_func = function()
{
if (obj.stat)
document.getElementById('BLAM').innerHTML = obj.reply;
}
obj = new xmlhttp();
obj.go('Try.php', do_func);
וזה הקוד בקובץ Try.php:
קוד PHP:
<?php
header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" ); // disable IE caching
header( "Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . " GMT" );
header( "Cache-Control: no-cache, must-revalidate" );
header( "Pragma: no-cache" );
echo 'text11';
?>
text2
<?php
echo 'Something';
?>
text33
|