来自另一个页面的jquery元素,带有$ .get

时间:2018-04-10 15:04:02

标签: javascript jquery

我正在尝试使用id = usertags从另一个页面中提取元素。我在使用.get方法。

出于某种原因,我无法实现,没有错误。

$.get('/cgi-bin/koha/opac-tags.pl', function(data) {
    var tags = $(data).find("#usertags");
    $("#mainuserblock").append(tags);
    console.log( $(data) );
});

我对日志信息$(数据)所说的内容感到困惑。对我来说,看起来它实际上并没有从opac-tags.pl页面中提取,而是来自其他地方:

{
  "length": 0,
  "prevObject": {
    "0": {
      "auth": {
        "0": {
          "0": {},
          "1": {},
          "2": {},
          "3": {},
          "4": {}
        },
        "1": {
          "0": {},
          "1": {},
          "2": {},
          "3": {},
          "4": {},
          "5": {}
        }
      },
      "searchform": {
        "0": {
          "0": {},
          "1": {},
          "2": {},
          "3": {},
          "4": {},
          "5": {},
          "6": {}
        },
        "1": {},
        "2": {}
      },
      "location": {
        "href": "http://viu.bywatersolutions.com/cgi-bin/koha/opac-main.pl",
        "origin": "http://viu.bywatersolutions.com",
        "protocol": "http:",
        "host": "viu.bywatersolutions.com",
        "hostname": "viu.bywatersolutions.com",
        "port": "",
        "pathname": "/cgi-bin/koha/opac-main.pl",
        "search": "",
        "hash": ""
      }
    },
    "context": {
      "auth": {
        "0": {
          "0": {},
          "1": {},
          "2": {},
          "3": {},
          "4": {}
        },
        "1": {
          "0": {},
          "1": {},
          "2": {},
          "3": {},
          "4": {},
          "5": {}
        }
      },
      "searchform": {
        "0": {
          "0": {},
          "1": {},
          "2": {},
          "3": {},
          "4": {},
          "5": {},
          "6": {}
        },
        "1": {},
        "2": {}
      },
      "location": {
        "href": "http://viu.bywatersolutions.com/cgi-bin/koha/opac-main.pl",
        "origin": "http://viu.bywatersolutions.com",
        "protocol": "http:",
        "host": "viu.bywatersolutions.com",
        "hostname": "viu.bywatersolutions.com",
        "port": "",
        "pathname": "/cgi-bin/koha/opac-main.pl",
        "search": "",
        "hash": ""
      }
    },
    "length": 1
  },
  "context": {
    "auth": {
      "0": {
        "0": {},
        "1": {},
        "2": {},
        "3": {},
        "4": {}
      },
      "1": {
        "0": {},
        "1": {},
        "2": {},
        "3": {},
        "4": {},
        "5": {}
      }
    },
    "searchform": {
      "0": {
        "0": {},
        "1": {},
        "2": {},
        "3": {},
        "4": {},
        "5": {},
        "6": {}
      },
      "1": {},
      "2": {}
    },
    "location": {
      "href": "http://viu.bywatersolutions.com/cgi-bin/koha/opac-main.pl",
      "origin": "http://viu.bywatersolutions.com",
      "protocol": "http:",
      "host": "viu.bywatersolutions.com",
      "hostname": "viu.bywatersolutions.com",
      "port": "",
      "pathname": "/cgi-bin/koha/opac-main.pl",
      "search": "",
      "hash": ""
    }
  },
  "selector": "response = {\n\tadded: 0,\n\tdeleted: 0,\n\terrors: 0\n\n\n};"
}

有没有人经历过这样的事情?

1 个答案:

答案 0 :(得分:0)

请参阅this question,特别是this answer

基本上,您应该将HTML上下文作为$的第二个参数传递:

$("#usertags", data);

或者,此语法也应该有效:

$("#mainuserblock").load("/cgi-bin/koha/opac-tags.pl #usertags");

但它会覆盖#mainuserblock的先前内容。