php - Write to file and send AJAX response at once -
update:
i used solution write data file. seems can't echo data while ajax waiting response. use fwrite.
$filehandle = ''; $filehandle = fopen("export.txt","w"); fwrite($filehandle, $export);
original:
hi there, maybe logic wrong. make ajax call data url. worked far.
but want add file export also.
$handler = new myhandler(); // step 1: data url $dataajax = $handler->getdata($_post['data']); // step 2: write data text file provide download $handler->writetotext($dataajax); echo json_encode($dataajax);
now console shows me "parsererror" because json data contains string wanted write file. that's bad , unwanted. below test how want write data txt file:
function writetotext($data) { header("content-type: text/plain"); header("content-disposition: attachment; filename=export.txt"); header("pragma: no-cache"); header("expires: 0"); $title = ""; $title .= "name,quantity,model,price,weight,status"."\n"; echo $title; }
that how error looks like:
{ "readystate": 4, "responsetext": "name,quantity,model,price,weight,status\n[{\"domain\":\"text\",\"name\":\"banana\}]", "status": 200, "statustext": "ok" } parsererror
Comments
Post a Comment