Heim  >  Fragen und Antworten  >  Hauptteil

javascript - ajax获取到某页面的html获取片段出错

用ajax获取某页面的html 测试ajax无错误 可能与dataType有关,但是目前用html和text均测试过不能用正则匹配

用js将ajax获取的页面提取 一下两种方法均不行

想知道是什么原因?

正则已经过测试

完整代码:

已解决,next_page_con_handler()应该放在ajax的success下

黄舟黄舟2721 Tage vor377

Antworte allen(3)Ich werde antworten

  • 黄舟

    黄舟2017-04-11 11:51:40

    $.ajax(...)
        .done(function(html) {
            // success() 里的内容可以写到这里来,然后不要 success 回调
            next_page_con_handler();
        });

    总的来说,是因为 ajax 还没返回,你已经执行了 next_page_con_handler(),数据还没取到呢,当然要报错。

    Antwort
    0
  • 巴扎黑

    巴扎黑2017-04-11 11:51:40

    你可以先将next_page_con打印到控制台看看。

    Antwort
    0
  • PHP中文网

    PHP中文网2017-04-11 11:51:40

    你把network截图发出来看看,我们现在还么有看到你的返回数据是什么。我猜测应该是变量指定的不对吧

    Antwort
    0
  • StornierenAntwort