Reputation: 1212
I have an Ajax call to create a new Quiz, with a link to the edit page of the quiz (using Laravel)
Now I have inside my JavaScript a PHP function, which therefor has a JavaScript variable again.
How is the variable data.id
inserted inside the php asset
function?
$('#newQuiz').click(function () {
var quizName = $('#quiz-name').val();
var url = "quizzes/store";
var token = '{{ csrf_token() }}';
$.ajax({
type: "POST",
url: url,
data: {
'name': quizName,
'_token': token
},
success: function (data) {
$('.quiz-table > tbody').append(
'<tr>' +
'<td>' + data.id + '</td>' +
'<td>' + data.name + '</td>' +
'<td>' + '<button type="button" class="btn btn-warning"><a href="{{ asset("quizzes/".+data.id+."/questions") }}">Edit Quiz</a></button>' + '</td>' +
'<td>' + '<button type="button" class="btn btn-success">Play Quiz</button>' + '</td>' +
'</tr>'
);
$('#quiz-name').val('');
}
});
});
This rule for clarification {{ asset("quizzes/".+data.id+."/questions") }}
Upvotes: 0
Views: 92
Reputation: 5982
How is the variable data.id inserted inside the php asset function?
You can't. PHP runs on the server, you can't set the value of a PHP variable via Javascript - the opposite is true though.
Upvotes: 2