homepage Welcome to WebmasterWorld Guest from 54.234.147.84
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Output received XML data to screen
Need to debug some ajax
Philosopher




msg:4543604
 10:29 pm on Feb 7, 2013 (gmt 0)

I had some code written for me (I'm not well versed with js and ajax) that posts data from a form and receives an xml response.

I'm having some issues and need to do a bit of debugging. To do that I need to see what is actually being received but since I've never been very handy with js much less ajax, I could use some help.

Here is the pertinent code below:


$.ajax({
type: "POST",
timeout:120000,
url: urltxt,
async: true,
data:tdata,
beforeSend: function() { $.mobile.showPageLoadingMsg("c","Processing...",false);
}, //Show spinner
complete: function() { $.mobile.hidePageLoadingMsg()
}, //Hide spinner


success: function(msg){
error = "";
$(msg).find('response').each(function(){

lots of code to test various responses...
});

Any help would be greatly appreciated!

 

Fotiman




msg:4543632
 11:55 pm on Feb 7, 2013 (gmt 0)

success: function(msg){
...
}

That is your success handler... the result of your POST. msg contains the data returned, so you could inspect that to see what was actually received. Most browsers today include developer tools that allow you to set breakpoints and inspect data at runtime. For example, in Chrome you can press F12 to open the Developer Tools, then find that line in the code and add a breakpoint. Then add the msg to the watch list.

Alternatively, you could do something like alert(msg) ;)

Philosopher




msg:4543841
 4:14 pm on Feb 8, 2013 (gmt 0)

Unfortunately, this script is part of an mobile app built with some phonegap, etc. so I can't use the dev tools available in FF or Chrome to inspect the received data.

I need to to include some code to print it to the screen itself.

I tried using commenting out everything after

success: function(msg){ to the closing brace and adding "alert(msg);", but got nothing.

Any other options would be appreciated. I'm definitely out of my comfort zone in js and ajax.

Fotiman




msg:4543864
 5:19 pm on Feb 8, 2013 (gmt 0)

When you say you "got nothing", does that mean you didn't even see an alert dialog? If so, that would suggest that your success handler was never reached.

I assume that the msg contains an XML document, which contains 1 or more <response> elements. Perhaps you could do something like:

$('body').append("<textarea id='debugOutput' rows='10' cols='30'><\/textarea>");
$('#debugOutput').val(msg);

drhowarddrfine




msg:4544306
 2:49 pm on Feb 10, 2013 (gmt 0)


...I can't use the dev tools available in FF or Chrome to inspect the received data.

Yes you can. https://developers.google.com/chrome-developer-tools/docs/remote-debugging

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved