Issue
Trying to append radio buttons but displays [object Object]. What could be the problem in my code?
.append('<li>'+JSON.parse(data.responseText).question+' ('+JSON.parse(data.responseText).score+'pts)
'+$.each(JSON.parse(data.responseText).choices, function(key, value){
{{Form::radio("radio", "value", ["class" => "form-control"])}}'
})+' ');
Console
choices: Array(4)
0: {id: 121, quiz_question_id: 91, choice: "B", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
1: {id: 122, quiz_question_id: 91, choice: "G", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
2: {id: 123, quiz_question_id: 91, choice: "C", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
3: {id: 124, quiz_question_id: 91, choice: "C1", created_at: "2019-11-21
05:35:42", updated_at: "2019-11-21 05:35:42"}
length: 4
Solution
$.each will not return the text. You will have to append the text within the callback. Please refer to the below sample:
HTML:
<label for="search_field">Address</label>
<input type='text' class='address_field' />
<li class="some_class"></li>
Javascript:
$(document).ready(function() {
var arr = [1,2,3];
$.each(arr, function(key,val) {
$('.some_class').append("(" + val + " )<li>sample1</li>");
});
});
Answered By - Arun Selin Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.