0

Firebug writes that request time of this script is 0 and add_comment_processor.php returns NULL.

$(document).ready(function(){
            $("#send_button").click(function(){
                var request = {
                    'comment': $("#new_comment_textfield").val(), //Value of textfield
                    'anonymously': $(".anonymously").is(':checked') //Value of anonymous check-button
                }
                $.ajax({
                    url: 'add_comment_processor.php',
                    type: 'post',
                    dataType: 'json',
                    success: function (data) {
                        var json = $.parseJSON(data);
                        alert(json); //returns NULL, but firebug writes that reques time of this script is 0ms
                    },
                    data: request //name of my object
                });
            });
        });

add_comment_processor.php
It just returns data it received so it shouldn't cause any problem.

<?php
unset($authorized_user);
session_save_path($_SERVER['DOCUMENT_ROOT'].'\session');
session_start();

$authorized_id=$_SESSION['authorized_user']; //logged user

// Read from POST
$recieve_data = file_get_contents('php://input');

// decode JSON
$object = json_decode($recieve_data);

$comment=$object->comment;
$anonymously=$object->anonymously;

$send_array=array(
    'comment'=>$comment,
    'anonymously'=>$anonymously
);

echo json_encode($send_array);
exit();
8
  • Why did you delete your previous identical question which had a comment asking for more info and clarification? Commented Nov 24, 2013 at 20:24
  • this is first time I use this site and I couldn't edit my question properly. when I type in script alert(request.comment); it shows true value of textfield Commented Nov 24, 2013 at 20:27
  • What does Firebug show in the response body of the Ajax request? Commented Nov 24, 2013 at 20:30
  • When your request type already is 'json', you don't have to use $.parseJSON(data);. Actually, $.parseJSON({}); returns null. What do you get when calling console.log(data) or alert(data)? Commented Nov 24, 2013 at 20:34
  • I am currently working on another computer with Chrome. Here are response headers: HTTP/1.1 200 OK Date: Sun, 24 Nov 2013 20:23:33 GMT Server: Apache/2.2.22 (Win32) mod_ssl/2.2.22 OpenSSL/1.0.1c PHP/5.3.13 X-Powered-By: PHP/5.3.13 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-Length: 35 Keep-Alive: timeout=5, max=98 Connection: Keep-Alive Content-Type: text/html; charset=UTF-8 Commented Nov 24, 2013 at 20:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.