在PHP,jQuery中自动更新状态而不刷新页面

时间:2013-08-30 06:52:38

标签: php jquery joomla

我想知道如何在按下按钮以更改其状态时自动更新表格列。

我的示例:我有一个按钮,用于从所选列的表中导出数据,一旦文件开始下载,我希望表中的某个字段使用“已导出”自动更新。

这就是我在没有集成自动过程的情况下编写的代码(现在它更新了状态,但您必须刷新页面才能使其生效)。

它是joomla中的一个项目,因此有一个Model,Controller和一个View。

型号代码:

public function export_to_csv($result, $values) {

    $headers="";

if ($values->export_csv == 1){
     $headers = "order_number|first_name|middle_name|last_name|email|shipment_name|payment_name|created_on|modified_on|order_status|order_total|virtuemart_order_id \n";

    }


    $shtml="";

        for ($i=0; $i<count($result); $i++){

            if ($result[$i]["export_status"] == 0 || $values->mark_csv == 0){

    $shtml = $shtml.$result[$i]["order_number"]. "|" .$result[$i]["first_name"]. "|" .$result[$i]["middle_name"]. "|" .$result[$i]["last_name"]. "|" .$result[$i]["email"]. "|" .$result[$i]["shipment_name"]. "|" .$result[$i]["payment_name"]. "|" .$result[$i]["created_on"]. "|" .$result[$i]["modified_on"]. "|" .$result[$i]["order_status"]. "|" .$result[$i]["order_total"]. "|" .$result[$i]["virtuemart_order_id"]. "\n";


            }
        }

        if ($shtml == ''){

            echo "false";

        }else{

            $shtml=$headers.$shtml;
            $_SESSION['txtDownload']=$shtml;

            echo "true";
        }

    exit;

}

控制器代码:

public function startDownload(){

    $db = JFactory::getDBO();
    $q = "SELECT prefix_csv FROM #__virtuemart_kiala_settings";
    $db->setQuery($q);
    $date = date("Ymd");

    $result=$db->loadResult();

    $shtml="";
    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=" .$result."_".$date. ".csv");
    header("Content-Transfer-Encoding: BINARY");    
    $shtml = $_SESSION['txtDownload'];

    echo $shtml;
    unset($_SESSION['txtDownload']);

    exit;

}

查看代码:

jQuery('#download').click(function() {

    var checks = countChecks();

    var checkCount = serializeChecks(checks);
    jQuery.ajax({
        url: "index.php?option=com_virtuemart&controller=kiala&task=prepareDownload",
        type: "post",
        data: checkCount,
        success: function(data){

            if (data=="true"){
                document.location.href = 'index.php?option=com_virtuemart&controller=kiala&task=startDownload';


            }else{
                alert('Error initializing download.');
            }
        }
    });
});

0 个答案:

没有答案
相关问题