How can I see the data that I passed through the following script?

    $('#btn_update').click(function(){
     $.post("../inc/set_session.php", {
       key: "phone_mode",
       value: "update"
       });
     var data = $('addform').serializeArray();
     $.post('phones_post.php', data);
       });
Member Avatar for diafol

What as an alert(data) or in the php as in $_POST['phone_mode]? You seem to have two ajax calls, to which one were you referring?

It shouldn't be necessary to make two AJAX posts for what is effectively one action.

You should be able to do a single $.post() thus simplifying both the client-side and server-side code, and avoiding the need to store the key/value pair in the Session, which (unless needed for another reason) is particlarly messy.

First, hard-code two hidden fields in your form, for example :

<input type="hidden" id="mode">
<input type="hidden" id="action">

Now you have the means of passing your mode and action data directly to the target script ('phones_post.php') along with the rest of the form data.

$('#btn_update').click(function() {
    var $form = $(this).closest("form");//create a jQuery-wrapped reference to the form element.
    $form.find("#mode").value('phone_mode');//put 'phone_mode' into the hidden 'mode' field.
    $form.find("#action").value('update');//put 'update' into the hidden 'action' field.
    $.post('phones_post.php', $form.serialize(responseData, String textStatus, jqXHR jqXHR)).done(function() {
        //$.post success code here
    }).error(function( jqXHR, textStatus, errorThrown) {
        //$.post failure code here
    });//post the serialized form fields.
});

The expression $(this).closest("form") assumes the 'Update' button to be within the form. If it is not, then the expression will be slightly different but the general principle is exactly the same.

Remember to change the mode and action values if the form is serialized and posted for other purposes.

To answer the actual question .... you can see the data submitted by temporarily changing type="hidden" to type="input" (twice). The rest of the form fields a presumably already visible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.