0

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)..

2
  • 1
    Are you sure that url: "../ajax-queries/update-user.php", is correct? I remind you that you must take into consideration the path where the PAGE where you add this <script> jquery file is and NOT where your jquery folder is when contructing the url parametre. Commented Jan 8, 2014 at 21:22
  • Yeah, I had good dir, in case I wouldn't get an empty Array() response :) however your offer might will help to others someday. Commented Jan 8, 2014 at 21:31

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Worked after I tried data:{update:u["..."]}, anyways.. is there a way to send an array?
are you sure ? try clear browser cache ... maybe the changes at the code aren't take effect (because it's cached.)
Worked! How I forgot about that.. THank you.. :)
0

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.

Comments

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.