[jQuery] Re: Round tripping XML data
For anyone else out there with a similar requirement, I have discovered/developed a simple solution to this which at least works with IE, Firefox and Safari and may work with other browsers that I have not yet tested... function XmlToString(xData) { if (xData.xml) { return xData.xml; } if (typeof XMLSerializer === 'function') { return (new XMLSerializer()).serializeToString(xData); } throw Unable to serialize XML data!; } If theres is a better solution I'd be interested to hear it :-)
[jQuery] Round tripping XML data
I'm hoping some can help me with the following... This is what I want to do... 1) Retrieve an XML data structure from the web server (easy enough using jQuery.ajax()). 2) Interrogate and update the data (again easy enough using standard jQuery methods against the XML DOM). 3) Post the modified XML data back to the server (for storage). Item #3 is the problem. As far as I know the only way to get the XML data back to the server is as a simple string. Is there a recommended way for serialising the XML DOM? I've looked at using: (new XMLSerializer()).serializeToString(xmlData); but the general consensus from looking at other posts is that this does not appear to be consistent/reliable across all browser platforms. Is there another, better way? Thanks.
[jQuery] Combining jQuery Objects
Does anyone know if it is possible to join two jQuery objects to make a new object. For example... var e1 = $(#firstObject); var e2 = $(#secondObject); var combined = e1.add(e2); // This is the expression I'm looking for Thanks.
[jQuery] Ajax: Posting Xml Data
Hi, I am trying to post an XML string back to an ASP.net page. The XML string is created in the client code and I am trying to use the jQuery.ajax() method... $.ajax({ type : POST, url : AjaxHandlerPage.aspx, data : { method : Save, data : xmlString }, contentType: text/xml, processData: false, dataType : json, cache : false, success : function(data) { // Process data here } }); When I call this method, I get a jQuery error s.data.match is not a function. If I remove the processData: false property the method runs, but I get a server error (I don't think I'm correctly processing the data on the server e.g. Request.Forms[method] does not work in this instance). So, in summary, I think I have two problems: 1) I don't know the correct way to post the XML data, and... 2) I don't know how to process (server-side) if I did! Does anyone have any experience in this process that they could share with me? Thanks.
[jQuery] Re: Ajax: Posting Xml Data
Yes, the xml structure at this stage (testing) is very simple, but the page throws and error before it gets to look at the data. The server returns a json string of the format {status: success} or {status: error} which would then be processed by the 'success' script. What seems odd is that jQuery throws an error before initiating the ajax call if I set the property 'processData: false' in the initialisation. For reference, the test xml is constructued as follows: var xml = menumenuItem name='Item 1' /menuItem name='Item 2' // menu; On May 9, 5:28 pm, andrea varnier [EMAIL PROTECTED] wrote: On 9 Mag, 17:17, NeilM [EMAIL PROTECTED] wrote: success : function(data) { // Process data here } what is this function supposed to do? it seems that it doesn't get the correct data (like the data var is empty or something). are you sure that your serverside script gives the correct answer? and what about the xmlString you're sending via post? is it exactly what the server is expecting? :)
[jQuery] Re: Ajax: Posting Xml Data
Thanks Mike, That helps a lot. I have modified the code back to a more 'default' setting and have found that all I needed to do was encode the xml string (using the escape() method) and then, of course decode the string on the server. If I don't encode/escape the xml, I get an ajax call error. $.ajax({ type : POST, url : AjaxHandlerPage.aspx, data : { method : Save, data : escape(xmlString) }, dataType : json, cache : false, success : function(data) { // Process return status data here } }); Neil. On May 9, 6:35 pm, Mike Alsup [EMAIL PROTECTED] wrote: What seems odd is that jQuery throws an error before initiating the ajax call if I set the property 'processData: false' in the initialisation. I think you've misunderstood the use of the processData option. That option lets the ajax function know whether it should convert the data arg to an encoded string or if that has already be done by the caller. You need your data to be processed because it is not in a format that can be sent to the server. It is a JavaScript object (which happens to contain some XML). In addition, the contentType setting is also wrong. Your content is not XML, is just happens to contain some. You should be using the default x-www-form-urlencoded content type. So your post data would ultimately look something like: method=Savedata=%3Cmenu%3E%3CmenuItem+name%3D'Item+1'+%2F%3E%3CmenuItem+name%3D'Item+2'+%2F%3E%3C%2Fmenu%3E Mike
[jQuery] Overriding jQuery Function
I would like to be able to 'override' a standard jQuery function to provide it with customised features and/or functionality whilst still being able to call the base/original function from within the new function to do the majority of the work. Is there a recommended approach to achieving this type of extension? [PS I originally posted this question on the Plugin Group - apologies]
[jQuery] Scope and Visibility from Callback
I want to create a 'closed' object (sorry, not sure what the right term is), e.g. var myObj = { foo : function() { $(#myLink).click(function(){ // How can I call the bar() method from here? What I would // really like to be able to do is call... // this.bar(); // But this doesn't work. // // The only way I can resolve it is by calling... // myObj.bar(); // Which doesn't make this class very flexible }); }, bar : function(){ } }; As indicated above, I want to be able to call another method in the object from within the contained jQuery event handler and I can't find an elegant/flexible way of doing this by referencing the object instance. Any advice would be appreciated.
[jQuery] Re: Selector Optimisation Question
Thanks Guys, That has been very helpful. On Jul 12, 4:52 pm, Michael Geary [EMAIL PROTECTED] wrote: Yeah, as Klaus mentioned, it is a tiny bit faster if you leave out the 'img'. The real optimization you can do is to avoid using the same selector repeatedly. In a way, jQuery makes it too easy to write inefficient code: $('#foo').doSomething(); // ...later... $('#foo').doSomethingElse(); Replace that with: var $foo = $('#foo'); $foo.doSomething(); // ...later... $foo.doSomethingElse(); As you can see, I use $variableName as a convention to remind me that the variable is a jQuery object. This will make more of a difference with slower selectors like $('.someClass'). Even though jQuery is much faster than it used to be, it's still faster if you can avoid repeating the selector query at all. -Mike From: NeilM I have just started to use jQuery in my web development and have a question concerning optimising element selection. I find that I create a lot of references to id'd elements: img id=myImage src=todaysimage.gif width=20 height=20 / Then, in my JavaScript, I want to obtain a reference to the element. Now, even though it has an id, I tend to use the full CSS descriptor as, to me anyway, it makes the code more readable: $(img#myImage).addClass(border); My question is, apart from the overhead of some extra characters in the script (e.g. 'img#'), does this style of specification introduce a performance overhead internally within jQuery? Would/does jQuery optimise the element selection process if it just 'sees' a simple id string starting with a #? $(#myImage).addClass(border);
[jQuery] Selector Optimisation Question
I have just started to use jQuery in my web development and have a question concerning optimising element selection. I find that I create a lot of references to id'd elements: img id=myImage src=todaysimage.gif width=20 height=20 / Then, in my JavaScript, I want to obtain a reference to the element. Now, even though it has an id, I tend to use the full CSS descriptor as, to me anyway, it makes the code more readable: $(img#myImage).addClass(border); My question is, apart from the overhead of some extra characters in the script (e.g. 'img#'), does this style of specification introduce a performance overhead internally within jQuery? Would/does jQuery optimise the element selection process if it just 'sees' a simple id string starting with a #? $(#myImage).addClass(border); Thanks.