Answer the question
In order to leave comments, you need to log in
Ajax + PHPExcel not working?
First time using PHPExcel
have ajax
$(document).ready(function () {
$('#exelTicket').submit(function (event) {
event.preventDefault();
var formValid = true;
var expolistall = $("#expolistall").val();
var formData = new FormData();
formData.append('expolistall', expolistall);
$.ajax({
type: "POST",
url: "ajax/exelticket.php",
data: formData,
contentType: false,
processData: false,
cache: false,
success: function (data) {
var $data = JSON.parse(data);
$('#error').text('');
if ($data.result == "success") {
$('#exelTicket').hide();
$('#msgExelTicket').removeClass('hidden');
} else {
$('#error').text('');
}
}
});
});
});
<?php
define('INCLUDE_CHECK',true);
require_once('../system/mysql.php');
require_once('../system/session.php');
require_once('../system/connect.php');
$data['result']='error';
function validStringLength($string,$min,$max) {
$length = mb_strlen($string,'UTF-8');
if (($length<$min) || ($length>$max)) {
return false;
} else {
return true;
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$data['result']='success';
if (isset($_POST['expolistall'])) {
$expolistall = $_POST['expolistall'];
if (!validStringLength($expolistall,1,500)) {
$data['expolistall']='Поля имя содержит недопустимое количество символов.';
$data['result']='error';
}
} else {
$data['result']='error';
}
}
else
{
$data['result']='error';
}
if ($data['result']=='success') {
//тут данные из базы, пока тестовый запуск так что их нет
require_once('../Classes/PHPExcel.php');
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B2', 'world!')
->setCellValue('C1', 'Hello')
->setCellValue('D2', 'world!');
$objPHPExcel->getActiveSheet()->setTitle('Название страницы');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
$data['result']='success';
}
echo json_encode($data);
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question