0

Here my javascript function:

var lastid = 0;
function charger() {
 setTimeout( function(){
 $.post(
 'http://localhost:8000/chat',
 {id: lastid},
 function(data) {
 $('#chat').prepend(data);
 }
 );
 charger();
 },5000);
}

Here my .php controller:

public function addMessagesAction(Request $request){
 $id = $request->request->get('lastid');
 $idall = $request->request->all();
 var_dump($id);
 var_dump($idall);
}

and my result from var_dump:

NULL array(0) { }

my question is:

How to get my "lastid" in my controller ?

asked May 13, 2016 at 10:31
4
  • You send the lastid variable from your javascript called as id, so you won't get never lastid in you php code. If you want to get lastid you have to send it as {lastid: lastid} in your javascript code. Commented May 13, 2016 at 10:35
  • i have change id by lastid in my javascript file but the result is same... Commented May 13, 2016 at 10:44
  • Can you show us all the relevant code for the question? For instance, the routing configuratoin whill be very intersting. Commented May 13, 2016 at 12:22
  • Then marks @dragoste answer as the valid one in order to close the question. Commented May 14, 2016 at 15:12

1 Answer 1

3

That's probably because yo've set in JS id param, not lastid. lastid is JS variable which is assigned to id param

{id: lastid}, //{name: value}

Therefore you should change it to:

{lastid: lastid},
answered May 13, 2016 at 10:34
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.