开发者

Iterating through Returned jQuery Data

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开发者_JAVA百科 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.


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() {
    // ....
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜