any one can help me please!
Jun 4, 2016
5
Level 3
Ajax request repeat the same value
I really searched for information more than a week, but I did not find solution. I work with ajax in laravel, my target is get value from post type attachment with ajax . the problem is ajax load only the first value wish I have a foreach loaded all my data on the model
This work but repeat the same value I have 6 question, but the request just repeat the first , not continue with 2, 3,4 5,6..etc. I want to be better, if you find something wrong with my code, please tell me how to improve. Thank you very much.
Question.blade.php
<?php $i = 0; ?>
@foreach ($questions as $question)
<h2>Welcome to The Accident Guys</h2>
<section data-step="<?php echo $i ?>" >
<div class="col-sm-12" id="headersection" >
<h4><b>Q.1</b></h4>
</div>
<div class="col-md-12 col-lg-12" style="padding-top:50px;">
<div style="background:gold">
<ul>
<li name="idquestion2" id="idquestion2" value="{{ $question->id }}">{{ $question->id }}
</li>
<li>{{ $question->content }}</li>
<li>{{ $question->a1 }}</li>
<li>{{ $question->a2 }}</li>
<li>{{ $question->a3 }}</li>
<li>{{ $question->a4 }}</li>
<li>{{ $question->a5 }}</li>
<li>{{ $question->a6 }}</li>
<li>{{ $question->a7 }}</li>
<li>{{ $question->a8 }}</li>
</ul>
<br>
</div>
</div>
</section>
<?php $i++ ?>
@endforeach
script.js
//after function..
e.preventDefault();
$.ajax({
type: "GET",
url: '/setQuestion',
data: {idquestion2:$('#idquestion2').val()},
cache: false,
success: function(data){
console.log(idquestion2);
}
});
var idquestion2 = $("#idquestion2").val();
mycontroller.php
public function setQuestion(Request1 $request){
$data = Input::all();
$idquestion2 = Request1::input('idquestion2');
if(Request2::ajax())
{
$user = Auth::user();
$history = new History();
$user_id = Auth::user()->id;
$history->user_id = $user_id;
$history->question_id = $idquestion2;
$history->user_resulat = 'Hell22o';
$history->save();
}
else{
dd('I am not ajax request');
}
}
Please or to participate in this conversation.