jquery ajax评估原始页面上的<script>标签</script>

时间:2013-07-24 19:14:02

标签: javascript html jquery

我有一个ul的网页,其li标记内生成script。我正在使用ajax将此列表传输到另一个页面。我想让ajax调用返回由script标签生成的内容(而不是script标签中包含的javascript),因为我无法访问接收到的页面上的相关变量内容。有没有办法做到这一点?

编辑: 我想要的内容是此页面上的列表:http://comunidad.winguweb.org/?t=368658

使用以下代码生成(注意:此代码将Liquid变量传递给Javascript。这些Liquid变量无法在ajax调用的接收端访问.ajax调用的要点是生成此列​​表然后传递它到了一个无法生成它的位置。我可能需要使用不是ajax的东西。):

<ul id='usuardest'>
  <li>testingbottom</li>
</ul>  
<script>
  var userarr = [];
  var len = 0;
  {% for topic in topics %}
    {% for question in topic.questions %}
      len = userarr.length;
      var femail = '{{ question.from_email | replace: "'","/'"}}';
      if (len == 0){
        userarr = [{fromemail: femail, helpful: 1, username: '{{ question.from_name | replace: "'","/'"}}'}]}
      else {
        for (var i = 0; i < len; i++) {
          if (userarr[i].fromemail == femail) {
            userarr[i].helpful ++; }
          else if (i == (len - 1)) {
            userarr.push({fromemail: femail, helpful: 1, username: '{{ question.from_name | replace: "'","/'"}}'}); }
        }
      }
      {% for answer in question.answers %}
        len = userarr.length;
        var femail = '{{ answer.from_email | replace: "'","/'"}}';   
        for (var i = 0; i < len; i++) {
          if (userarr[i].fromemail == femail) {
            userarr[i].helpful ++; }
          else if (i == (len - 1)) {
            userarr.push({fromemail: femail, helpful: 1, username: '{{ answer.from_name | replace: "'","/'"}}'}); }
        }
      {% endfor %}
    {% endfor %}
  {% endfor %}
  userarr.sort(function(productA, productB){
    return productB.helpful - productA.helpful
  });
  var udest = document.getElementById('usuardest');
  for (var i = 0; i < 5; i++) {
    udest.innerHTML = udest.innerHTML + "<li>" + userarr[i].username + userarr[i].helpful + "</li>";
  }
</script>

我用来获取它的ajax查询是:

var debug;
$(function() {
  $.ajax({
  type: "GET",
  url: "http://comunidad.winguweb.org/?t=368658",
  dataType: "html",
  success: parseHTMLagain
  });
});

我用来合并查询结果的解析函数是:

function parseHTMLagain(html) {
  "use strict";
  $(html).filter('#usuardest').appendTo('#listadestac');
}

1 个答案:

答案 0 :(得分:0)

显然<iframe>有效......