我是json中的新成員。我使用php從mysql表中生成jason數據,並希望將生成的json導出爲.xls格式。使用Jquery Easyui將datagrid導出爲excel
examexport.php
<?php
include 'conn.php';
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$semester = isset($_POST['semester']) ?
mysql_real_escape_string($_POST['semester']) : '';
$entry = isset($_POST['entry']) ? mysql_real_escape_string($_POST['entry']) : '';
$batch = isset($_POST['batch']) ? mysql_real_escape_string($_POST['batch']) : '';
//phpexcel things go here
?>
我的PHP產生JSON:
{"total":"6","rows":
[{"id":"2","regd":"25","name":"Lalhmangaihsangi","class":"BA",
"rollno":"3","univ_roll":"UNVI573","univ_no":"MZU876","core":"Education",
"semester":"First","batch":"2014","subject":"Education",
"entry":"Second Internal Test","date":"2014-07-23",
"score":"55","fm":"100","remark":"She is guarded"}]}
代碼導出到Excel:
<input type="button" onclick="exportExcel()" value="Export to Excel " />
<script>
function exportExcel(){
$('#dg').datagrid('load',{ //load data by semester/batch/entry
semester: $('#semester').val(),
batch: $('#batch').val(),
entry: $('#entry').val(),
document.location='excel/examexport.php'// How do I include entry/batch/ here?
});
}
</script>
我想送點東西像document.location =」 excel/examexport.php?entry = entry & batch = batch & semester = se mester' 我得到一個ReferenceError exportExcel未定義。
你試過 - >'document.location ='excel/examexport.php?entry ='+ $('#semester').val()+'&batch =' + $('#batch')。val()+'&semester ='+ $('#entry')。val()' – Sean
@Sean,我已經試過了,但它不起作用。 –