Creating xml Document In javascript shows error - javascript

I am trying to create a xml document in Javascript. but it will not give required output
Here is my code
if(status==0)
{
var objXML = new ActiveXObject("Microsoft.XmlDOM")
objXML.async = false
var objXMLRoot=objXML.createElement("root")
objXML.documentElement=objXMLRoot
objXMLRoot.appendChild(objXML.createElement("parentname"))
objXMLRoot.appendChild(0).text=listid
objXMLRoot.appendChild(objXML.createElement("childname"))
objXMLRoot.appendChild(1).text=document.getElementById("childId").value;
objXMLRoot.appendChild(objXML.createElement("childstatus"))
objXMLRoot.appendChild(2).text=ichildid;
AjaxSend(objXMLRoot,'100','1');
}
My problem : i did't get any data in my xml document . i want to get listid,childid values in my xml document
any help will be appriciated

Their is some syntax error in your code
try something like below
if(status==0)
{
var objXML = new ActiveXObject("Microsoft.XmlDOM")
objXML.async = false
var objXMLRoot=objXML.createElement("root")
objXML.documentElement=objXMLRoot
objXMLRoot.appendChild(objXML.createElement("parentname"))
objXMLRoot.childNodes(0).text=listid
objXMLRoot.appendChild(objXML.createElement("childname"))
objXMLRoot.childNodes(1).text=document.getElementById("childId").value;
objXMLRoot.appendChild(objXML.createElement("childstatus"))
objXMLRoot.childNodes(2).text=ichildid;
AjaxSend(objXMLRoot,'100','1');
}

Related

How to retrieve all-suggestion-accepted content of a Document on google Doc through API

As title, I manage to retrieve all-suggestion-accepted content on Google Docs through API. I have referred to its guideline and a couple of posts on this platform but in vain. Below is the snippet I currently have. Please Advise.
function myFunction()
{
var documentId ="My file ID";
var doc = Docs.Documents.get(documentId);
var SUGGEST_MODE= "PREVIEW_SUGGESTIONS_ACCEPTED";
var doc1 = Docs.Documents.get(documentId).setSuggestionsViewMode(SUGGEST_MODE);
console.log(doc1.body.content)
}
Upon seeing the documentation, you should use it like this
Script:
function myFunction() {
doc_id = '1s26M6g8PtSR65vRcsA90Vnn_gy1y3wj7glj8GxcNy_E';
SUGGEST_MODE = 'PREVIEW_SUGGESTIONS_ACCEPTED'
suggestions = Docs.Documents.get(doc_id, {
'suggestionsViewMode': SUGGEST_MODE
});
new_content = '';
suggestions.body.content.forEach(obj => {
if(obj.paragraph)
obj.paragraph.elements.forEach(element => {
new_content += element.textRun.content;
});
});
console.log(new_content);
}
Sample suggestions (with added paragraph):
Output:
EDIT:
Added an additional paragraph, and instead of just logging them, I have stored them in a single variable and printed at the end.
Reference:
documents.get

displaying existing html pages (one at a time) in tool

I am building a tool in which I am trying to open a html file having single column or multiple column. I want to get each section of html file to be displayed in the display section of my tool as we do so in the browser.My javascript code for display page is:
function open(htmlFile) {
var htmlFile1 = htmlFile;
alert(htmlFile1);
var parser = new DOMParser();
var doc = parser.parseFromString(htmlFile, "text/html");
var all = doc.getElementsByTagName("body");
var sections = doc.getElementsByClassName("section");
alert(sections);
}
I think you want to get all section of your HTML page.If there is no custom class or ID on it then you have to get by getElementsByTagName("section").
Below is the code snippet may help you:
var htmlFile="<html><body><p>Hello World!</p><p>We're here</p><section><h1>WWF</h1><p>The World Wide Fund for Nature (WWF) is....</p></section></body></html>";
function open(htmlFile) {
var htmlFile1 = htmlFile;
alert(htmlFile1);
var parser = new DOMParser();
var doc = parser.parseFromString(htmlFile, "text/html");
var all = doc.getElementsByTagName("body");
var sections = doc.getElementsByTagName("section");
$.each(sections, function() {
alert(this.innerHTML);
});
}
open(htmlFile);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

Dynamically change text based on URL input

I am using the following code to dynamically change the text on my clients website (www.mydomain.com.au):
<script type="text/javascript">// <![CDATA[
var url = window.location.toString();
var query_string = url.split("?");
if (query_string[1]) {
var params = query_string[1].split("&");
var param_item = params[0].split("=");
param_item[param_item[0]] = unescape(param_item[1]);
document.write(param_item["city"]);
} else {
document.write("24 Hour Glass Replacement");
}
// ]]></script>
It works perfectly fine on the index page. e.g. www.mydomain.com.au/?city=test
but when I am using the same code on other pages e.g. http://www.mydomain.com.au/Brisbane.html/?city=test I get a 404 error.
Appreciate any help
Remove the / before starting querystring. So,
try http://www.mydomain.com.au/Brisbane.html?city=test instead of http://www.mydomain.com.au/Brisbane.html/?city=test

Javascript: Getting values from XML file

This is my exact xml file:
<?xml version="1.0" ?>
<blah_de_blah>
<unblocker_details table_color="#F2F0FF" type="zip" alt_link="http://g.org/288"
link_for_deletion="3-QQ5DJoa-AWFT7a9" comment="zippy" />
<unblocker_details table_color="#FFFFFF" type="Webpage" alt_link="http://www.gg.com"
link_for_deletion="4-rOX2brr-2qQeGY3" comment="test" />
</blah_de_blah>
I have successfully gotten it via an ajax request, then did this:
var xmlDoc=null;
var parser = new DOMParser();
xmlDoc = parser.parseFromString(data, "text/xml");
and now I need to get each of those values from unblocker_details into a variable:
for example:
the_table_color=table_color;
the_type =type;
etc
Please also check if I declared the xml properly as I am very new to this.
Thanks!
Something like this:
var nodes = xmlDoc.getElementsByTagName("unblocker_details");
for(i=0; i< nodes.length; i++) {
the_table_color = nodes[i].getAttribute("table_color");
// get other attributes the same way
}
You can use this http://www.w3schools.com/ajax/ajax_xmlfile.asp

body html of iframe

Hi my code returns all the html of the iframe. I would like just the body html. Any one know how to amend to suit?
Code:
alert( $("#uploaderIframe").contents()[0].documentElement.innerHTML );
var iframeHtml = $("#uploaderIframe").contents()[0].documentElement.innerHTML;
var bodyHtml = $(iframeHtml).find("body").html();
alert( bodyHtml );
.. probably creates a new DOM node from the innerHTML of the iFrame - I actually suspect that $(iframeHtml).find("body") is an empty jQuery object.
Try
var bodyHtml = $('#uploaderIframe').contents().find("body").html()
Ref: Traversing/contents
Try this:
iframeHtml = $("#uploaderIframe").contents()[0].documentElement.innerHTML;
bodyHtml = $(iframeHtml).find("body");

Categories

Resources