AJAX equivalent of file_get_contents()
Posted: Wed Sep 12, 2007 11:47 am
Is there any AJAX equivalent of file_get_contents in PHP ??
I was trying to make one but cant.
But this is not working.e.g. the function is not returning the text response
I was trying to make one but cant.
Code: Select all
function ajx_obj(){
var xmlhttp=false;
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E){
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined'){
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}Code: Select all
function get_file(file_name){
var tmp_str;
var request = ajx_obj();
request.open('GET', file_name, true);
request.onreadystatechange = function(){
if(request.readyState == 4){
if(request.status == 200){
tmp_str = request.responseText;
}
}
}
request.send(null);
return tmp_str;
}