ajax: returns whole html page instead of xml content only
Posted: Tue Jul 10, 2007 9:14 am
feyd | Please use
but for some reason when i use ajax, i get a lot of current page html content returned in http responseText. Could any of you please tell me why this is happening?
javascript code:
for a demo, please try the link 'generate xml for links' from http://thisisraghavan.com/misc/links.php and see the html content appended after xml output in the textarea box dynamically generated.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i have a 'link management' system. this allows to store links. i have an option to generate xml file for all the links available. it generates a xml of format.Code: Select all
<Links>
<Link>
..
..
</Link>
...
...
</Links>javascript code:
Code: Select all
core.js
//global var: will be used by many functions
var http = createRequestObject();
//create xmlHTTP obj
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}
function sndReq(sendMethod, url, event) {
//alert( 'sendMethod: ' + sendMethod + ' url: ' + url + ' event: ' + event );
http.open( sendMethod, 'http://' + url, true);
http.onreadystatechange = function(){
//alert( 'http state: ' + http.readyState + 'event: ' + event );
if(http.readyState==4){
// Get the data from the server's response
if( event == 'generateXML' ){
//alert( 'generateXML event matched' );
generateXMLForLinks( http.responseText );
}
}
}
http.send(null);
}
links1.js
function generateXMLForLinks( input ){
//var sendMethod = 'get';
//var url = 'thisisraghavan.com/misc/links.php?action=generateXML';
//var input;
//input = sndReq( sendMethod, url );
//alert( 'generateXMLForLinks called' + 'input: ' + input );
var output = '<textarea cols="80" rows="5">' + input + '</textarea>';
document.getElementById( 'output' ).innerHTML = output;
}
call line:
<a href = 'javascript:sndReq("get", "thisisraghavan.com/misc/links.php?action=generateXML", "generateXML")'>Generate XML for Links</a>
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]