我有一些简单的jquery运行,我想让它运行一些我正在调用的ajax请求......但是jquery不能在任何ajax请求中工作。
这是我使用的jquery插件:
我正在调用这样的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 ..甚至没有注册它们......任何帮助?
感谢
答案 0 :(得分:1)
听起来好像绑定没有在正确的时间发生。
尝试使用jQuery live绑定您的活动
答案 1 :(得分:0)
您可以使用jQuery来处理所有AJAX混乱:
$(document).ready(function() {
$.ajax({
url: "/test/test.html",
success: function(response) {
// here you can use "response"
}
});
});