Jquery不加载Ajax请求,这是可能的

Jquery not loading for Ajax request, is it possible?

本文关键字:加载 Ajax 请求 Jquery      更新时间:2023-09-26

我有一些简单的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…它甚至不注册它们…任何帮助吗?

,

谢谢

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

尝试使用jQuery实时绑定你的事件

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

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