2011-10-10 27 views
0

我有一些簡單的jquery運行,並且我希望它能夠運行某些即時通訊調用的ajax請求......但jquery不能在任何ajax請求中工作。Jquery沒有加載Ajax請求,可以嗎?

這裏是jQuery的使用插件IM:

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 ..他甚至不註冊他們...任何幫助?

 

感謝

+0

你並不需要在您的問題,使用直HTML。 http://stackoverflow.com/editing-help –

+0

請正確格式化您的問題,刪除那些&nbsp等。 – vzwick

+1

如果您可以使用jQuery,爲什麼不把它用於AJAX呢? –

回答

1

這聽起來像結合不是在正確的時間發生。

嘗試使用jQuery live綁定您的活動

+0

似乎沒有把戲 – nate

0

您可以使用jQuery採取一切AJAX亂七八糟的護理:

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

謝謝! def清理ALOT更好:D。 – nate