创建一个请求:
var loadScript = function( src, callback ) {
var head = document.getElementsByTagName( 'head' ),
script = document.createElement( 'script' );
if( script.addEventListener ) {
script.addEventListener( 'load', callback, false );
}
else if( script.attachEvent ) {
script.attachEvent( 'onreadystatechange', function() {
callbackIE( callback );
});
}
script.src = src;
head.appendChild( script );
};
var callbackIE = function( callback ) {
var target = window.event.srcElement;
if ( target.readyState == 'loaded' ) {
callback.call( target );
}
};
引用:
var url = 'http://localhost/index.php?test=test';
loadScript( url, function() {
alert( ResponseData );
});
PHP (index.php):
$test = $_GET['test'];
echo 'ResponseData = "' . $test . '"';