php - retrieve data send via ajax post -


i have following ajax code sending data php via post:

          checked_id = 10;           $.ajax({                url: "/delete_document",                type: "post",                data: {id:checked_id}, //                success: function(data, textstatus, jqxhr){                     alert(data);                     location.href='/delete_document';                },                error: function (jqxhr, textstatus, errorthrown){                     //alert('error!')                }           }); 

it prepares data successfully, , correct value alerted (10).

then should fetch value in php file:

$selected_id = $_post['id']; var_dump($selected_id); 

but var_dump gives me string(0) "".

i know when code doesn't work, it's me 1 that's doing wrong. can not see mistake here.

the thing see after code has completed is not result of post ajax call, it is result of redirection in line

location.href='/delete_document'; 

and makes second call /delete_document url time simple request without post data expect have.

edit.

instead of making ajax call , redirecting page want move /delete_document post data. can't redirecting should make form , submit in javascript.

here's example of you're trying do: javascript post request form submit


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -