Jump to content

jquery ajax posts input default value


Agony
 Share

Recommended Posts

its related to the thread:http://w3schools.invisionzone.com/index.php?showtopic=50396

 

But i found that javascript related questions are better suited for this forum, rather then php.

        var results = $('[name^=id]').map(function(){               var $this = $(this);            var $defaultid = this.defaultValue;                        $($this).on('focusout',function(e){                var $id = $($this).val();                if ($id != $defaultid){                    console.log($id);                    console.log($defaultid);                    $($this).css('background-color', '#FFA07A');                                 $.ajax                ({                    url: 'index.php?action=ticket_ajax',                    type: 'post',                    data: {'id': $id, 'defaultid': $defaultid, 'page' : 'update'},                    success : function(data) {                    console.log(data);                    }                                  });                                };            });          });

Problem with the code above is that the ajax submits $id as default value, instead of the changed value.:{"id":"999","defaultid":"999"} is the json it returns to the console.Id should be 1 - the console.log right before the ajax prints 1 to the console.So why does ajax suddenly get a different value for it right after?

Link to comment
Share on other sites

That wouldn't be happening, nothing is changing $id inside the if statement. You will be able to verify with your browser developer tools that the request going out contains the correct ID. It's more likely that the JSON being returned by PHP is not correct.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...