Skip to main content

Posts

Convert String to XML Document in JavaScript

Saw this example on the jQuery examples page for Ajax: var xmlDocument = [create xml document]; $.ajax({ url: "page.php", processData: false, data: xmlDocument, success: someFunction }); How do I take a string like: var t = '<foo><bar>something</bar></foo>'; And convert that to a XML DOM object? cross-browser? UPDATE : Please see comments to karim79's answer. Source: Tips4all

How can I erase all inline styles with javascript and leave only the styles specified in the css style sheet?

If I have the following in my html: <div style="height:300px; width:300px; background-color:#ffffff;"></div> And this in my css style sheet: div { width:100px; height:100px; background-color:#000000; } Is there any way, with javascript/jquery, to remove all of the inline styles and leave only the styles specified by the css style sheet? Source: Tips4all

jQuery / Ajax - $.ajax() Passing Parameters to Callback - Good Pattern to Use?

JavaScript code I'm starting with: function doSomething(url) { $.ajax({ type: "GET", url: url, dataType: "xml", success: rssToTarget }); } Pattern I would like to use: //where elem is the target that should receive new items via DOM (appendChild) function doSomething(url, elem) { $.ajax({ type: "GET", url: url, dataType: "xml", success: rssToTarget(elem) }); } I don't think I can get the callback to work this way, right? What is the proper pattern? I don't want to use global variables necessarily to temporarily hold the elem or elem name. Source: Tips4all

Cannot properly set the Accept HTTP header with jQuery

I'm trying to set the Accept HTTP header to "text/xml" with this jquery code: $.ajax({ beforeSend: function(req) { req.setRequestHeader("Accept", "text/xml"); }, type: "GET", url: "[proper url]", contentType: "text/plain; charset=utf-8", dataType: ($.browser.msie) ? "text" : "xml", username: '---', password: '-------', success: function(data) { var xml; if (typeof data == "string") { alert("Data is string:" + data); xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = false; xml.loadXML(data); } else { xml = data; alert("Data is not string:" + $(xml).text()); } // Returned data available in object "xml" //alert("Status is: " + xml.

get root URL in javascript

is there a really easy way to turn document.location.href=="http://aaa.bbb.ccc.ddd.com/asdf/sadf/asdf/asdf/asdf/sadf.aspx?blah" into 'aaa.bbb.ccc.ddd.com'? There's gotta be a JS function that does this reliably, but I can't find it. Source: Tips4all