2016-10-14 47 views
0
$bid="http://congress.api.sunlightfoundation.com/legislators?chamber=$chamb&state=$keyword&bioguide_id=$bname&apikey="; 
$text=$text."<td id=><a href='#'>Details</a>"."</td>"; 

這是我的代碼,$bid是我的url,它返回json數據。我想發送一個url到另一個php函數

我想發送這個url到另一個php函數,它可以解析它並在瀏覽器上打印。

+0

如果您想在用戶點擊某個內容時調用PHP函數,則需要使用AJAX。 – Barmar

+0

我不能使用ajax!必須完成沒有ajax – codeZach

+0

我已經完成了它使用隱藏變量和JavaScript函數調用。感謝你所有的迴應。 – codeZach

回答

0

試試這個:

<script type="text/javascript"> 

    $(document).ready(function() { 

    $("#btn").on("click", function() { 
      var link = "webservice.php"; 
      $.get(link, function(data, status){ 
      alert("Data: " + data + "\nStatus: " + status); 
      }); 
     }); 
    }); 
</script> 
0

使用file_get_contents獲得通過API返回的數據,並json_decode()將其轉換爲PHP數組。

鏈接應指向包含這樣的代碼腳本:那other_function()打印將被髮送到瀏覽器

<?php 
$bid="http://congress.api.sunlightfoundation.com/legislators?chamber=$chamb&state=$keyword&bioguide_id=$bname&apikey="; 
$json = file_get_contents($bid); 
$data = json_decode($json, true); 
other_function($data); 

一切。

相關問題