2009-02-24 25 views
0

這裏是我的shop.html片段:

<li><a id="linkShop" href="shop.html">shop</a></li> 
<div id="paneMiddle"></div> 

,這裏是我main.js片段:

$("a[id=linkShop]").click(function(){ 
    $.get("data1.html", function(response){ 
     $("div[id=paneMiddle]").html(response); 
     alert("hi"+ response); 
    }); 

}); 

data1.html有這內容:

<p>data 1 - test</p> 

我真的不知道爲什麼會這樣,現在,我已經在PHP嘗試$不用彷徨之前, 但現在,我嘗試使用jquer y w/jsp,運行在tomcat服務器上。 idk爲什麼在我的$ .get()函數中沒有任何內容。

幫助me..pls ... TT

回答

4

你是不是取消點擊鏈接點擊事件的默認操作,所以當你點擊鏈接,你只重新加載頁面的$不用彷徨獲得前任何迴應。

嘗試

$("a[id=linkShop]").click(function(){ 
     $.get("data1.html", function(response){ 
       $("div[id=paneMiddle]").html(response); 
       alert("hi"+ response); 
     });  
     return false; 
}); 

$("a[id=linkShop]").click(function(evt){ 
     $.get("data1.html", function(response){ 
       $("div[id=paneMiddle]").html(response); 
       alert("hi"+ response); 
     });  
     evt.preventDefault(); 
}); 
+0

謝謝。這工作。出現警報。但是響應不會出現在div w/id = paneMiddle中。 :( – 2009-02-24 07:08:33

+0

如果你用$('div#paneMiddle')來引用它,它會起作用嗎? – kkyy 2009-02-24 07:22:44

0

如何不使用< A>標記爲你的點擊目標..也許只使用一個跨度來代替?

<li><span id='linkShop' style='cursor:pointer'>shop</span></li> 
<div id="paneMiddle"></div> 

,然後簡單地

$("#linkShop").click(function() { 
    $("#paneMiddle").load("data.html"); 
}); 
0

嘗試取消您的鏈接的默認行爲與event.preventDefault:

$("a[id=linkShop]").click(function(event){ 
     event.preventDefault(); 
     $.get("data1.html", function(response){ 

       $("div[id=paneMiddle]").html(response); 
       alert("hi"+ response); 
     });  
}); 

您可以測試你的生活腳本here,並且可以修改你的阿賈克斯加載內容here

0

嘗試這一個

$("a#linkShop").click(function(){ 
    $.get("data1.html", function(response){ 
      $("div#paneMiddle").html(response); 
      alert("hi"+ response); 
    });  

});

相關問題