Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Mar 2005
    Messaggi
    140

    $_POST internal error 500

    Ciao a tutti,
    ho un problema con una semplice funzione, vorrei passare un dato da una funzione javascript ad un file php, cosi ho implementato queste funzioni:
    PHP
    codice:
    <?php
    $data = $_POST['data'];
    echo json_encode($data);
    ?>
    JAVASCRIPT
    codice:
    $(window).load(function(){
            $('#export').click(function() {
    			$.ajax({
    				type: "POST",
    				url: "creaFile.php",
    				data: "francesco",
    				success: function(response){
    					window.alert(response);
    				//	window.location.href = response.url;
    				}
    			})
    		});
    	});
    il problema è che appena faccio partire la funzione il response è nullo, questo ovviamente porta ad avere internal error 500 appena cerco di fare una funzione piu complessa che può essere questa:
    codice:
    <?php
    
    $data = $_POST['data']; // get the data from the AJAX call - it's the "data: grid.getData()" line from above
    
    /** Error reporting */
    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);
    date_default_timezone_set('Europe/London');
    
    if (PHP_SAPI == 'cli')
    	die('This example should only be run from a Web Browser');
    
    /** Include PHPExcel */
    require_once 'Classes/PHPExcel.php';
    
    $countryArray = array($data,'USA','GERMANY','FRANCE','BELGIUM','SWEDEN','JAPAN','CHILE','BOTSWANA','SRI LANKA');
    
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->removeSheetByIndex(0);
    
    foreach($countryArray as $ck =>$cv) {
        $sheet = $objPHPExcel->createSheet($ck);
        $sheet->setTitle($cv);
        $sheet->setCellValue('A1', $cv.' '.$ck);
    }
    
    $objPHPExcel->setActiveSheetIndex(0);
    
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('CountrySheets.xls');
    
    $response = array(
        'success' => true,
        'url' => 'CountrySheets.xls'
    );
    
    header('Content-type: application/json');
    
    // and in the end you respond back to javascript the file location
    echo json_encode($response);
    
    ?>
    sapete darmi una mano?

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2009
    Messaggi
    636
    Il parametro data dovrebbe contenere una query string o un oggetto in formato json. In ogni caso servono coppie chiave valore. La chiave 'data' non esiste per come l'hai scritto tu.

    Cosi dovrebbe andare:
    codice:
    data: ({'data':'francesco'})

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.