2013-07-21 22 views
0

我有一個頁面,其中包含所有變量解析。第一頁執行所有數據庫請求並將變量傳遞給包含。我們的雲框架意味着我們無法直接從網絡訪問文件,但我可以直接包含它們。如何使用jQuery Ajax刷新一個php include?

get_responses($platform_id, $platform_name, $gettab, 10, $redirect, $redirecttab, $id, "1"); 

調用下面的函數

function get_responses($platform_id, $platform_name, $type, $number, $redirect, $redirecttab, $challenge = "", $type_no){ 
$api_url = datasepia('api:url'); 
$api_id = datasepia('api:id'); 
$api_key = datasepia('api:key'); 

$usr_name = ""; 
$usr_key = ""; 


XYZ below... 

回答

1

這是相當困難的,幫助你因你沒有給我們具體的「系統」, 任何信息,你說我們的事你的cdn api ..但它是我們需要知道的不太有用的東西

所以我假設你不知道該怎麼辦,這裏是一個普通的方法

我們的雲框架意味着我們無法直接從 網站訪問文件,但我可以直接包含它們。

,所以你只需要一個PHP包裝來調用這些「包括」,讓你的數據

<?php 
    // read your args and if need sanitize them 
    $id = $_POST['link']; // read your args 

    // do the job and get/generate your data 
    $mydata = get_responses($id, ... your api ...); 

    //if you need json or anything else, it's now 
    $mydata = json_encode($mydata); 

    // here print/die the data 
    die($mydata); // echo and return 
?> 

在JavaScript端,你將調用包裝與所需的信息, 取決於從哪裏啓動該活動,您存儲所需的信息

這裏的一個例子,我假定這就是所謂的點擊經典錨標記,並使用HREF作爲args作爲腳本

HTML:

<a href="/page2">my page 2</a> 

的jQuery:

// catch all anchor click 
$(document).on('click','a',function(event){ 
    var $this = $(this); // current clicked anchor as a jquery object 
    var href = $this.attr('href'); // get the link href 

    // construct your ajax args 
    var ajaxArgs = { link:href, hello:"world" }; 

    /* made an ajax call by jQuery, here i use post, check jQuery documentation */ 
    $.post('/my_php_ajax_listener.php', ajaxArgs, function(dataReturnByPhp){ 
     /* if here ajax has terminated, do anything with the data, 
     * here we will fill #content html node with the data, assume data is here pure html */ 
     $("#content").html(dataReturnByPhp); 
    }); 

    event.preventDefault(); // no real click please 
}); 

好運

+0

我想發佈更多,但它是一種很難不給所有的代碼進行公開。無論如何私下討論這種事情? – steve0nz

+0

只是適應您的獲取數據api的ajax PHP包裝,當它沒事你只會得到JavaScript的一部分來創建,誰更能夠公然顯示 – r043v