2011-12-10 12 views
1

私はPHPを使用してXMLファイルを解析し、異なるストーリーにタイトルを表示しています。私は会社に基づいて物語をフィルタリングする選択メニューを持っています。私はこれが働いているが、ページをリフレッシュする。誰かがAjax経由でこれを行う方法の例を私に提供して、ページ全体がリフレッシュされないようにすることはできますか?どんな助けもありがとうございます。jQuery update選択メニュー値の変更時にPHPの変更

ライブ例:http://recoverstudio.com/test/

現在のコード:

<form name="feed-form" action="" method="GET"> 
    <select name="feed" onchange="this.form.submit();"> 
    <option value="">Filter</option> 
    <option value="https://www.pitchengine.com/Feed/AgencyRss/036d17f9-50ff-4cf1-9273-8865ba82d9ff">All</option> 
    <option value="http://pitchengine.com/Feed/BrandRss/cf6f4ba5-5e43-47c8-a7f2-1a9cb490c639">Brand 1</option> 
    </select> 
</form> 

<div id="press-releases"> 
    <div id="pitch-engine"> 
    <?php 
     $url = 'https://www.pitchengine.com/Feed/AgencyRss/036d17f9-50ff-4cf1-9273-8865ba82d9ff'; 
     if(isset($_GET['feed'])){ 
      $url = $_GET['feed']; 
     } 
     $xml = simplexml_load_file($url); 

     echo '<table>'; 
     echo '<tr class="head"><td>Date</td><td>Title</td></tr>'; 
     foreach($xml->channel->item as $item) 
     { 
      echo '<tr>'; 
      echo '<td>' . $item->pubDate . '</td>'; 
      echo '<td><a href="' . $item->link . '">' . $item->title . '</a></td>'; 
      echo '</tr>'; 
     } 
     echo '</table>'; 
    ?> 
    </div> 

答えて

0

基本的には、jQueryの.changeイベントにAJAX呼び出しを作りたいです。

このような何かが(未テスト)それを行う必要があります。

$('#myselect').change(function() { 
    var url = $(this).find('option:selected').val(); 
    $.ajax({ 
     url:url, 
     type:'GET', 
     success: function (res) { 
      // res should contain your XML string - parse it 
     } 
     error: function (xhr, status, errorThrown) { 
      console.log(status+' - '+errorThrown); 
      alert('Something went wrong processing the request.'); 
     } 
    }); 
}); 

あなたは、おそらく自分自身を解析するXMLを整理することができます - 私は経験をJavaScriptでJSONをパースしています。

関連する問題