maddisoncr
asked on
issue returning a json Id variable
I am guessing this is going to be a huge oversight on my part but i have an issue with json that i havent been able to resolve..
i am using the following code to run an update/insert query
my php statement returns a response with the following :
Essentially, all that i want to do is to return the last inserted ID whenever i have a new record. at the moment, when i alert the response, i get {"lastId":"0"}.. but when i try response.lastId it returns undefined ?
I'm not sure where i'm going wrong or if i'm even doing this with the right approach ?
Thanks
i am using the following code to run an update/insert query
$.post($("#updateEnquiryform").attr("action"),$("#updateEnquiryform").serialize(),function(){
}).success(function(response){
alert(response);
alert(response.lastId);
},"json");
my php statement returns a response with the following :
$result->execute();
$insertedID = $pdo->lastInsertId();
$returnUrl = array ("lastId"=>$insertedID);
echo json_encode($returnUrl);
Essentially, all that i want to do is to return the last inserted ID whenever i have a new record. at the moment, when i alert the response, i get {"lastId":"0"}.. but when i try response.lastId it returns undefined ?
I'm not sure where i'm going wrong or if i'm even doing this with the right approach ?
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
excellent
No worries - sometimes just needs a fresh pair of eyes :)
ASKER
i'd been hacking around and hadn't even noticed the first function.
all working as it should now
thanks again