I'm fairly new to web development and php.
I have a js file with all my functions. In one of the functions I make an ajax call to create a new database record that person A is making a challenge to person B.
JS
var challengeeId = document.getElementById('Challengee').value;
$.ajax({
type:"post",
url: baseUrl+"/site/challenge",
data:{"challengeeId":challengeeId},
cache:false,
success: function(html){
}
});
PHP
$model = new Challenge();
$model->challenger_id = Yii::app()->user->id;
$model->challengee_id = $_POST['challengeeId'];
$model->date_created = date("Y-d-m H:i:s");
$model->status ="pending";
$model->save();
This is fine and saves in table correctly. The table also creates an id for every challenge. I want to know how to return that id so that I can store it as a variable in my JS file for later use. I have an SQL query which returns the ID for me, I just don't know how to return it from the PHP to JS.