2012-02-27 34 views
0

我與一些腳本玩,在這裏使用jQuery檢索數據是我:從PHP文件

<!doctype html> 
<html> 
<head> 
    <title>Home page</title> 
    <link rel="shortcut icon" href="/images/favicon.ico" /> 
    <link rel="icon" href="/images/favicon.ico" type="image/x-icon" /> 
      <link rel="stylesheet" href="/css/base.css" type="text/css" media="all" /> 
      <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/themes/base/jquery-ui.css" type="text/css" media="all" /> 
      <link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" /> 
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> 
      <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js" type="text/javascript"></script> 
      <script src="http://jquery-ui.googlecode.com/svn/tags/latest/external/jquery.bgiframe-2.1.2.js" type="text/javascript"></script> 
      <script src="http://jquery-ui.googlecode.com/svn/tags/latest/ui/minified/i18n/jquery-ui-i18n.min.js" type="text/javascript"></script> 


    <script type="text/javascript"> 
     function get() { 
      $.post('data.php', 
       function(output) { 
        $('#container').html(output).show(); 
      }); 
    </script> 
</head> 
<body> 

    <script> 
    $(function() { 
     $("#tabs").tabs(); 
    }); 
    </script> 
<div class="demo"> 

<div id="tabs"> 
    <ul> 
     <li><a href="#tabs-1">Статии</a></li> 
     <li><a href="#tabs-2">Коментари</a></li> 
     <li><a href="#tabs-3">Европа</a></li> 
     <li><a href="#tabs-4">Свят</a></li> 
    </ul> 
    <div id="tabs-1"> 
     <a id="BB" onClick="get();">Тайният проект Бойко Борисов</a> 

    </div> 
    <div id="tabs-2"> 
     <p>Защо се изкупува земя от северозападна България</p> 
    </div> 
    <div id="tabs-3"> 
     <p>Бъдещето на Гърция</p> 
    </div> 
    <div id="tabs-4"> 
     <p>Мястото на САЩ е политиката на ЕС</p> 
    </div> 
</div> 
<div id="container"> 

</div> 
</body> 
</html> 

後來我想用data.php文件從連接到數據庫並提取數據那裏,但現在我只想讓它適用於存儲在data.php中的任何數據。

我使用這個腳本,其中我認爲是主要的問題:

<script type="text/javascript">    
    function get() { 
     $.post('data.php',    
     function(output) {       
      $('#container').html(output).show();      
    });   
</script> 

,我想將數據放在<div id="container></div>

最後的想法是從菜單中加載鏈接集裝箱div,我試着這樣做:

<div id="tabs-1"> 
    <a id="BB" onClick="get();">Тайният проект Бойко Борисов</a> 

data.php我只是一個echo "Hello world";但諾斯當我點擊鏈接時會顯示。我想有超過1個問題,但任何幫助表示讚賞。

謝謝,勒龍。

+1

你在控制檯中看到任何錯誤...? – 2012-02-27 10:30:15

+0

在控制檯選項卡中帶有螢火蟲的FireFox中,您可以監控您的ajax請求。因此,您可以進一步調查問題出在哪裏,例如:找到了php文件,這個php文件返回什麼,我發送了什麼參數。代碼似乎是正確的。 – 2012-02-27 10:30:55

+0

這是我使用JQuery的第一天,我很確定這個錯誤在某處,但我不確定它是語法,邏輯還是兩者。我已經用純AJAX完成了它工作,但我想用JQuery來做。 – Leron 2012-02-27 10:33:11

回答

2

你應該關閉get()函數的作用域。

function get() { 
      $.post('data.php', 
       function(output) { 
        $('#container').html(output).show(); 
      }); 
    } 

你剛剛忘記了大括號。


$。員額( 「test.php的」,{名字: 「約翰」,時間: 「2:00」},功能(數據){});

你可以發送這樣的發佈數據。

你想選擇標籤或wannaa發送一些數據?

$('#BB').click(function() { get(); }); 

您可以將函數綁定到上面的代碼。

這是你想要的嗎?

+0

你是完全正確的。謝謝,現在我明白了我應該做的。系統允許我接受你的問題。但是對於第二部分 - 我看到我應該在$ .post('data.php',使用花括號{}}旁邊放置一些代碼,以便我可以選擇標記,並單擊我單擊的元素,coukld you help如何從上面的代碼中選擇ID =「BB」的? – Leron 2012-02-27 10:41:24

+0

我已經添加了一些內容,請檢查它是否是你想要的? – littlealien 2012-02-27 10:47:41

+0

這就是我需要的 - $('#BB')。click function(){get();}); 感謝您的幫助! – Leron 2012-02-27 10:57:20