Link to home
Start Free TrialLog in
Avatar of maddisoncr
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

$.post($("#updateEnquiryform").attr("action"),$("#updateEnquiryform").serialize(),function(){
	
}).success(function(response){
	alert(response);
	alert(response.lastId);
},"json");

Open in new window


my php statement returns a response with the following :

$result->execute();
$insertedID = $pdo->lastInsertId();
$returnUrl = array ("lastId"=>$insertedID);
echo json_encode($returnUrl);

Open in new window



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
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of maddisoncr
maddisoncr

ASKER

thanks chris, you're absolutely right..

i'd been hacking around and hadn't even noticed the first function.

all working as it should now

thanks again
excellent
No worries - sometimes just needs a fresh pair of eyes :)