0

so i've been looking at how to record and send client-side data to a php server.

i'm not sure of the correct terminologies, but i think that using an ajax call to send a post to the php server is the most elegant way to solve this problem.

so i decided to implement this data exchange:

$("#"+activityInfo.ID).click(function(){
window.open(activityInfo.URL+"userId="+$("#userid").val()+"&activityId="+activityID+"&classId="+classID);
 classid = classID;
 activityid = activityID;
 $("body").append("class: " + classid);
 $("body").append("id: " + activityid); 
 $.post('http://chemcollective.org/chemvlab/php/updateProgress.php', { 'cid':classid ,  'aid':activityid } );}); //i think this is the important line that sends the data

and the corresponding php file (updateProgress.php)

$class_id = $_POST['cid']; //receives the data
$activity_id = $_POST['aid'];

i'm not sure why this is the case, but class_id and activity_id variables always return an empty value.

i understand somewhat that the client-browser is on a page that is preloaded by information from a php server. but there were posts that said this is a possible way to communicate back to the php server with information from the client. i'm not really sure what is going on b/c at this point i don't really know what questions to ask.

one of the example explanations that i had been following: Ajax passing data to php script

thanks for the help.

i've also played around with start_session() and storing/loading session variables as a way to transfer data information. this works but only for php <-> php communication. it does not for saving javascript variables, so i couldn't really use $_SESSION = ..... in my javascript code.

Community
  • 1
  • 1
jason
  • 3
  • 2
  • are you sure that you get the `cid` and `aid` value properly from javascript? also check the browser console for `CORS` error. – Jaison Justus Jun 15 '14 at 07:43

1 Answers1

0

you need to get the cid and aid outside of the single-qouts while using $.post! try this:

$.post('http://chemcollective.org/chemvlab/php/updateProgress.php', { cid:classid ,  aid:activityid } );
Amin Jafari
  • 7,157
  • 2
  • 18
  • 43