简体   繁体   中英

Extract Data From XMLHttpRequest .responseText

I have a fully functioning .php which utilizes XMLHttpRequest to Post data back to itself. What I'm looking to do is making the response a little more friendly for the user rather than me simply displaying a JS alert() when the function completes.

How can/should I access particular portions in the response rather than the entire response. For example, I could...

document.getElementById('result').innerHTML = "Received:<br>\n" + xmlhttp.responseText;

...to grab all of it. Can I simply pull individual pieces out with document.getElementByid()??

Thanks.

You cannot call those methods on the responseText, but you can call them on responseXML - see http://msdn.microsoft.com/en-us/library/ms534370(v=vs.85).aspx for an example. The responseXML property will contain a DOM and you can use standard DOM methods there (assuming of course, your server is actually sending back XML - if not, you are on your own for parsing the responseText)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM