views:

30

answers:

1

Hi All,

I have a form which I'm using jQuery to post and working to handle the return data.

I currently have the following :

$.ajax({
    type: 'POST',
    url: '/',
    data: $("#register_member_form").serialize(),
    success: function(data){
        if (data.search(/error/) >= 0)
        {
        var err = "There were errors found in your entry.\nPlease check your :\n";

        if (data.search(/submit a username/) >= 0) {err += "\tUsername\n"}


        alert(err);
        }
        else
        {
        location.replace( $("#RET").val() );
        }

And what I'm doing is using the data.search('') function to look for keywords and then appending to the err variable and alerting that at the end.

However, there are quite a lot of system generated error messages, so what I'm looking for is a solution that will iterate through the returned data and look for the values of <li></li> and then alert that.

Normally if it were standard HTML, I would do a ("li").each(function(){}) etc to get it, but since it's a data stream variable - how would I accomplish it? is it possible?

Many Thanks all!

C.

A: 

You can parse your data using your standard jQuery functions:

success: function(data){
  var $data = $(data); // creates the DOM elements from the text data!
  if ($data.find('.error').length) {
    var $errors = $data.find('ul.errors li').each(function() {
    // ....
gnarf
perfect - thats worked a treat! C.
Carl Crawley