【问题标题】:Jquery not loading for Ajax request, is it possible?Jquery 没有为 Ajax 请求加载,这可能吗?
【发布时间】:2011-10-10 23:58:52
【问题描述】:

我有一些简单的 jquery 可以运行,我希望它与一些我正在调用的 ajax 请求一起运行...但是 jquery 不能在任何 ajax 请求中工作。

这是我正在使用的 jquery 插件:

http://fancybox.net/

我这样调用fancybox插件:

<a href="http://5.mshcdn.com/wp-content/uploads/2011/10/141,acer_aspire_s3.jpg" class="mybox" >

现在这部分工作正常。我可以拥有多个这样的链接,并且所有这些链接都会很好地加载精美的框 Jquery 插件。

问题是当我尝试通过 ajax 请求加载这些类型的数据时:

function ajaxTest(){
    var ajaxRequest;  // The variable that makes Ajax possible!

    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){

                        var txt = ajaxRequest.responseText;

            document.getElementById('myid').innerHTML = txt ;
        }
    }
    ajaxRequest.open("GET", "/test/test.html", true);
    ajaxRequest.send(null); 
}

test.html 与上面的链接基本相同,带有 mybox 类...唯一的区别是它不加载 jquery..它甚至不注册它们...有什么帮助吗?

 

谢谢

【问题讨论】:

  • 您不需要在问题中直接使用 HTML。 stackoverflow.com/editing-help
  • 请正确格式化您的问题,去掉那些 &nbsp 等
  • 如果你能用jQuery,为什么不把它也用在AJAX上呢?
  • 请让您的问题更清楚,以便我们提供帮助。
  • 很抱歉没有意识到结果全错了。道歉

标签: javascript jquery ajax


【解决方案1】:

听起来绑定没有在正确的时间发生。

尝试使用jQuery live 绑定您的事件

【讨论】:

    【解决方案2】:

    您可以使用 jQuery 来处理所有 AJAX 混乱:

    $(document).ready(function() {
      $.ajax({
        url: "/test/test.html",
        success: function(response) {
          // here you can use "response"
        }  
      });
    });
    

    【讨论】:

    • 谢谢! def 清理得更好:D.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多