The Kat's Work - Blog
Main | Blog | Registration | Login
Thursday
2024-05-02
11:57 PM
Welcome Guest | RSS

Just come up against this bad boy. So thought I’d provide the solution.

 
So you’re getting the very descriptive Javascript Error: Expected identifier, string or number in IE. What’s worse when you use firefox, which is infinitely better for debugging JavaScript it works just fine. Don’t worry the solutions is quite simple. My error was caused by the code below.



Can you see the problem? Me Neither. It turns out that IE in its infinite wisdom cannot handle empty JavaScript array elements. So in the code where I have put {backgroundColor: "#FDD017”, } (which to be fair was an over sight) makes IE freak out.




So the solution is simple make sure you don’t leave trailing commas. Oh by the way the code creates a dialog if the user click "Go to Data …” it scrolls slowly(using the scroll to plugin for jquery) to the data quality than makes the input fields in my data Quality section flash yellow. Fixed Code below.


Views: 1085 | Added by: The_Kat | Date: 2010-03-24 | Comments (0)


I recent problem i had was just how to parse xml returned by ajax.

I know a few of you will scream JSON at me but i have done quite a bit using ajax and xml in the past so there;-).

You can use standard javascript for this(as i have) but as ever jQuery provide tools to do the same functions in just a few lines. When you need to RAD this is very helpful.

So first off lets see how JQuery handles an xmlDocument below.

<root>
<clients>
<client id="1">
<surname>Kat</surname>
<forename>The</forename>
</client>
<client id="2">
<surname>Kat2</surname>
<forename>The</forename>
</client>
</clients>
</root>

The first thing to do is cast the xmlDocument to a jQuery object.

var jXML = $(xml);

Now to select elements we can use the .find() method. 

This really is where jQuery excels. simply put .find(name) will find all element(s) named name.

var clients = $(jXML).find('client');

Notice we can bypass the clients element and go straight to client. We could also just get all surnames in a similar way.

Now to access the properties we either use .attr() method for attributes or the .text() method for text contents.

$(clients).each(function() {
alert($(this).attr('id'));
});

// would give alert 1 and alert 2

$(clients).each(function() {
alert($(this).find('surname').text());
});

// would give alert Kat and alert Kat2

So lets add it all together with the marvellous $.ajax() method.

function retrieveClients(){ $.ajax({ url: "retrieveClients.html", cache: false, type: "GET", dataType: "xml", success: function(xml){
$(xml).find('client').each(function(){
alert($(this).find('forename').text() );

alert($(this).find('surname').text() ); }); } }); };

Views: 1248 | Added by: The_Kat | Date: 2010-03-04 | Comments (0)


Very busy at the moment thanks to several projects.

Coming soon:

jQuery review.
css Layouts.
continuing with optimisations.
Views: 994 | Added by: The_Kat | Date: 2010-02-19 | Comments (0)

« 1 2 ... 9 10 11 12 13 »
Login form
Adverts
Search
Calendar
«  May 2024  »
SuMoTuWeThFrSa
   1234
567891011
12131415161718
19202122232425
262728293031
Entries archive
Site friends
  • Create your own site
  • Spree4.com
  • My Blog
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    spree4
    Copyright MyCorp © 2024
    Website builderuCoz