2010-11-24 74 views
0

我正在運行代理,所以我可以通過url參數對數據執行ajax請求。代理PHP的樣子:通過代理傳遞url屬性

<?php 
header('Content-type: application/xml'); 
$daurl = 'http://thesite.com/form.asp'; 
$handle = fopen($daurl, "r"); 
if ($handle) { 
    while (!feof($handle)) { 
     $buffer = fgets($handle, 4096); 
     echo $buffer; 
    } 
    fclose($handle); 
} 
?> 

我打阿賈克斯在結束了附加參數,如代理:

$j.ajax({ 
      type: 'GET', 
      url: 'sandbox/proxy.php', 
      data: 'order=' + ordervalue, 
      dataType: 'html', 
      success: function(response) { 
      $j("#result").html(response); 
      } 
     }); 

所以請求是像沙箱/ proxy.php順序= 123

我該如何獲取數據(order = 123)並將其附加到$ daurl變量(http://thesite.com/form.asp?order=123),以便我可以讓代理實際返回一些內容?

這是一塊處女地,我所以你不能過度解釋=)

回答

2

簡單。

$daurl = 'http://thesite.com/form.asp'; 

//if you only want 'order': 
if(isset($_GET['order'])) 
    $daurl .= '?order=' . $_GET['order']; 

//if you want the entire query string: 

if(strlen($_SERVER['QUERY_STRING']) > 0) 
    $daurl .= '?' . $_SERVER['QUERY_STRING']; 
... 
+0

太棒了!非常感謝。 – Zac 2010-11-24 18:38:00

0

$_SERVER['QUERY_STRING']應包含訂單= 123,所以你可以改變$ daurl如下:

$daurl = 'http://thesite.com/form.asp'; 
if($_SERVER['QUERY_STRING'] != ""){ 
    $daurl.='?'.$_SERVER['QUERY_STRING']; 
} 

這樣做,這樣將傳遞查詢字符串上傳遞的所有內容。但是,如果你只想要的順序部分可以使用$ _GET [「秩序」],你可能想要做的事,如:

$order = isset($_GET['order']) ? $_GET['order'] : -1; 

$order將是-1,如果訂單中沒有查詢字符串中傳遞,否則它會有價值。