I am using laravel 5.4, my Ajax functionality is called twice every time due to which I create two users however I want to create one user per click
actually it includes another page and that page don't have its on
$(document).ready(function(){
or any function like
$(document).on('click','#addproject',function(){
but they includes script tags but if I don't include them then Ajax is called only once Ajax call:
$(document).on('click','#addproject',function(){
$.ajax({
type:'get',
url:"{!! URL::to('addProject') !!}",
data:{},
success:function(data){
console.log('success');
console.log(data);
console.log(data.length);
$("#newproject").fadeIn();
},
error:function(){
},
});
});
Routes:
Route::get('/addProject','HomeController@addProject');
Controller:
public function addProject(Request $request){
$project = new Project;
$data = array(
);
$project->create($data);
}
I solved it, it turns out to be I was loading this page using load()
, but I should have loaded this page using window.location.href = "updateform";
Very basic mistake though.
and solution might was my app specific.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With