本文介绍了jquery遍历$ .get的结果(url,function(data){的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道遍历此函数返回的数据的正确语法是什么:

I'm wondering what the correct syntax is to traverse the data returned of this function:

$.get(url, function(data){
            alert(data);
        });

data.find(table)或类似的不起作用。
返回的html数据如下所示,从django模板解析:

data.find("table") or similar does not work.The returned html data looks like this, parsed from a django template:

<div class="pagination"> 
        <span class="step-links"> 

            <span style="visibility:hidden;">previous</span> 
            <span class="current"> 
                    Page 1 of 2.
            </span> 
            <a id="next" href="?page=2">next</a>  
        </span> 
    </div> 

        <form class="" id="action-selecter" action="" method="POST"> 
        <div class="action_dropdown"> 
            <label>Action: <select name="action"> 
                <option value="" selected="selected">---------</option> 
                <option value="new_selection">Add to new selection</option> 
                <option value="delete_selected">Delete selected projects</option> 
            </select></label> 
            <button type="submit" class="button" title="Run the selected action" name="index" value="1">Go</button> 
        </div> 

        <div id="ajax_table_result"> 
            <table cellspacing="5"> 
                ...
                </thead> 
                    <tbody> 
                     ...

                    </tbody> 
            </table> 
        </div> 
    </form> 


推荐答案

请记住将结果包装在jQuery包装器中使用反对它的jQuery方法。

Remember to wrap your results in the jQuery wrapper to use jQuery methods against it.

$.get("script.php", {foo:"bar"}, function(results){
  var table = $("table", results);
  /* from comments: how to get span.step-links */
  var spans = $("span.step-links", results);
}, "html");

这篇关于jquery遍历$ .get的结果(url,function(data){的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:01