javascript - Fetching xml with GM_xmlhttpRequest -


I am trying to retrieve a page with greasemonkey and to remove a link again, Enter the link in the page. I'm having some trouble with this:

  GM_xmlhttpRequest ({method: "GET", url: "http://www.test.net/search.php?file=test", Onload : Function (data) {if (! Data.responseXML) {data.responseXML = new DOMParser (.) ParseFromString (data.responseText, "text / xml");} alert ("!"); Var xmldata = data.response .xml; var test = xmldata.getElementsByTagName ('test'); warning (test [0] .winnerHTML);}});  

This page is valid, and GM_xmlhttpRequest has correctly returned it as a string, when I tried earlier, but I can not seem to understand that it How to do so that I can use the node operation on it thanks in advance.

Editing - A second, related question

How do I refine the current page so that I can pass it to work, as I Will the received page be passed? Pre

  function fastcut (current page) {currentpage.getElementById ('blah'); }  

Where initially I pass this document, but later I used the fetched page. Sorry if the word is misleading.

If the requested page is a well-formatted XML, you can do it correctly.
But you should change data from response.xml to data. ResponseXML

and I think that you do not Do this with XMLDocument (the result of XML parser) because .getElementById works in HTMLDocument .
However, you can do this to keep a valid HTMLDocument:

  if (/ ^ content-type: text \ / xml / m.test (data.responseHeaders) ) {Data.responseXML = new DOMParser (). ParseFromString (Data.responseText, "text / xml"); } Else if (/ ^ content-type: text \ / html / m.test (data.responseHeaders)) {var dt = document.implementation.createDocumentType ("html", "- // W3C // DTD HTML 4.01 transitional / / N "," http://www.w3.org/TR/html4/loose.dtd "); Var Doctor = Document. Implementation.createDocument (tap, tap, dt); // I want to get an alternative solution because this technique disappears HTML * / head / body tag. Var html = document.createElement ('html'); Html.innerHTML = Data Transcript text; Doc.appendChild (HTML); Data.responseXML = Doctor; }  

Source:


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -