colap Posted January 7, 2014 Share Posted January 7, 2014 (edited) $("input.class_input_button_send").on("click",function(event) { event.preventDefault(); //var username = $("input.class_input_hidden").val(); var typed_text = $("input#id_input_text_type").val(); console.log(typed_text); rt = $.ajax({ type: "POST", url: "send.php", data: { name: "", typed_text: typed_text }, success: function(data) { console.log(data); console.log(data.length); } }).done(function() { alert( "success" ); }) .fail(function() { alert( "error" ); }); //console.log(rt); }); send.php =><?php <?php if( session_id() == '' ) { session_start(); } if($_SERVER['SERVER_PROTOCOL'] == "HTTP/1.1") { $domain_host_root = "http://" . $_SERVER['SERVER_NAME'] . "/"; } require_once 'core/model/mysql/mysqldb.php'; require_once 'core/utility/debug-app.php'; require_once 'core/utility/utility.php'; require_once 'core/view/view.php'; //$_POST['typed_text'] = "abc"; $typed_text = $_POST['typed_text']; $objDateTime = new DateTime('NOW'); $target_file = $objDateTime->format("Y-m-d"); $handle = fopen("archive/" . $target_file . ".txt", "w+"); fwrite($handle, $target_file_data); echo json_encode($target_file); ?> fopen function is working inside that send.php script if i run this as a standalone script, but fopen function returns null through the jquery $.ajax() function. Edited January 7, 2014 by php-coder Quote Link to comment https://forums.phpfreaks.com/topic/285158-php-fopen-is-not-working-through-jquery-ajax/ Share on other sites More sharing options...
Solution GetFreaky Posted January 7, 2014 Solution Share Posted January 7, 2014 (edited) PHP-coder, Add dataType: "json" to your function params. $.ajax({dataType: "json", url: url, data: data, success: success }); Edited January 7, 2014 by GetFreaky Quote Link to comment https://forums.phpfreaks.com/topic/285158-php-fopen-is-not-working-through-jquery-ajax/#findComment-1464204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.