Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery从另一个页面获取DIV内容_Jquery - Fatal编程技术网

jQuery从另一个页面获取DIV内容

jQuery从另一个页面获取DIV内容,jquery,Jquery,我有以下代码: <script> $( document ).ready(function() { $("div.imp-1 span.field-content").each(function() { var $li = $(this); var href = $li.find("a").attr("href") + ".htm"; // use this in your real case //console.log (href); $.ajax

我有以下代码:

<script>
$( document ).ready(function() {
$("div.imp-1 span.field-content").each(function() {
    var $li = $(this);
    var href = $li.find("a").attr("href") + ".htm";  // use this in your real case
    //console.log (href);
    $.ajax({
        type: "POST",
        success: function(data) {
            var time = $(data).find('.time-default').html();
            $li.append(" - " + time);
        }
    });
});

});
</script>

$(文档).ready(函数(){
$(“div.imp-1 span.field content”)。每个(函数(){
var$li=$(本);
var href=$li.find(“a”).attr(“href”)+“.htm”//在实际案例中使用此选项
//console.log(href);
$.ajax({
类型:“POST”,
成功:功能(数据){
var time=$(data.find('.time default').html();
$li.追加(“-”+时间);
}
});
});
});
HTML页面包含一些HTML,如下所示

<div class="time-default">22:15 - 23:30</div>
22:15-23:30
它不断返回“未定义”-我做错了什么


谢谢

您需要传递其他页面URL

$.ajax({
    url: href,  //Pass URL here 
    type: "GET", //Also use GET method
    success: function(data) {
        var time = $(data).find('.time-default').html();
        $li.append(" - " + time);
    }
});

您在
$.ajax()
中缺少
url:href
,谢谢-尽管页面位于同一服务器上(实际上是此文件的子文件夹),但我收到了405错误。有什么想法吗?只需要允许HTML页面接收帖子!我想念的那些简单的事情——呸!非常感谢。