JDSolutions
JDSolutions

Reputation: 115

Stock with sending data with jQuery to PHP file

I'm trying to send data via POST to PHP file.. $.get() - works fine, hovewer I couldn't tell the same about $.post() or $.ajax() with method post.. Here my code I wrote:

$('[name="update"]').click(function(){
    tr = $(this).parents('tr');
    u = [];
    u["username"] = tr.find('[name="u[username]"]').val();
    u["display_name"] = tr.find('[name="u[display_name]"]').val();
    u["type"] = tr.find('[name="u[type]"]').val();

    $.ajax({
        type: "POST",
        url: "../ajax-queries/update-user.php",
        data: {update:u},
        cache: false,
        success:  function(data){
           alert(data);
        }
     });

});

And PHP file looks like:

<?php 
     print_r($_POST);
?>

Response I get:

Array(
)

Using latest jQuery lib... no ideas why not working.. any solutions you can offer? Is that could be posible because of port:2014? in case i tried and in :80 (same results)..

Upvotes: 0

Views: 83

Answers (2)

Moussawi7
Moussawi7

Reputation: 13267

Array with key index is not an array, it's an object, try alert(typeof u). sending an array with key index will fail in IE8.

Upvotes: 0

Andrey
Andrey

Reputation: 1496

Because you aren't setting anything.
Try changing u to {}, like: u = {};

Upvotes: 1

Related Questions