2011-03-06 53 views
0

我想从ajax get调用中通过id选择一个脚本节点。jquery select script node get get

<script id="jqgrid_js" type="text/javascript"> 
... 
</script> 

get调用:

  $.get(url, function(results){ 
       console.debug(results); //the jqgrid_js is included in the result 
       console.debug($('#jqgrid_js')); //this returns the node from the actual page 
       console.debug($('#jqgrid_js', results)); // in the result I can not select it 
       var jqgrid_js = $('#jqgrid_js', results); 
       //do the update 
       $('#jqgrid_js').html(jqgrid_js); 
      }, "html"); 

我想知道为什么同样的SELECT语句不返回节点,而节点肯定是包含在“结果”变种。

+0

的'context'不能是一个HTML字符串:http://api.jquery.com/jQuery/ – 2011-03-06 12:19:43

+0

ok了,我有什么更改? – 2011-03-06 12:25:22

回答

0

尝试扭转这一点,并使用find代替:

var jqgrid_js = $(results).find('#jqgrid_js'); 
+0

不会改变任何内容。在此期间,我发现这一点:http://stackoverflow.com/questions/4430707/trying-to-select-script-tags-from-a-jquery-ajax-get-response .. – 2011-03-06 13:21:49