Trying to save file using php and ajax

时间:2016-04-25 09:07:53

标签: php jquery ajax

Need to save some big data to file on server

"/php/test.php":

<?php if(!empty($_POST['data'])){
    $data = $_POST['data'];
    $fname = mktime() . ".txt";
    $file = fopen("upload/" .$fname, 'w');
    fwrite($file, $data);
    fclose($file);
    }
?>

jquery:

var data = 'foo bar';
$.ajax({
    url: 'php/test.php',
    type: 'POST',
    data: { data: data },
    success: function(result) {
        alert('the data was successfully sent to the server');
    }
});

result:

405 (HTTP method POST is not supported by this URL)

what's the problem?

0 个答案:

没有答案