У меня есть определенный HTML моей формы в create.blade. php и его js в форме. js. Я хочу отправить данные формы из сценария java в хранилище функций контроллера EventsContoller laravel. Каждый раз, когда я нажимаю кнопку отправки, тот же URL загружается с '?' в конце. Может ли кто-нибудь решить мой вопрос? Вот код:
**EventsController.php**:
public function store(Request $request)
{
//The controller function code
}
**create.blade.php**:
The code for the form opening and closing and the submit button.
@extends('inc.navbar')
@include('inc.messages')
@section('content')
<body>
<!-- BEGIN:CREATE FORM-->
<div class="row">
<div id="my_container">
{!! Form::open(['class'=>'event-details col s12 m12 l12 p-0', 'id'=>'form'])!!}
//The form code
{!!Form::close()!!}
<form class="buttons">
<div class="row center-align m-0">
<div class="submit_form">
<button class="btn waves-effect waves-light submit" id="submit">SUBMIT</button>
<button class="btn waves-effect waves-light">BACK</button>
</div>
</div>
</form>
**form.js**:
The function for submitting the form data sending data to the controller's store function.
$('#submit').click(function(e) {
var start_dates = [];
var end_dates = [];
var start_times = [];
var end_times = [];
var no_of_days = $("#no_of_days").val();
for (var i = 0; i < total_rows_of_dates; i++) {
var start_date = $('#start_date' + i).val();
start_dates[i] = start_date;
var end_date = $("#end_date" + i).val();
end_dates[i] = end_date;
var start_time = $("#start_time" + i).val();
start_times[i] = start_time;
var end_time = $("#end_time" + i).val();
end_times[i] = end_time;
let current_date = new Date();
if (end_date < start_date || new Date(start_date) < current_date || new Date(end_date) < current_date) {
console.log('Please put different date');
}
if (start_time >= end_time) {
console.log('Please put different time');
e.preventDefault();
}
if (department.val() == "" || title.val() == "" || description.val() == "" || fees.val() == "" || speaker.val() == "") {
console.log("Please enter all details");
e.preventDefault();
}
}
console.log(start_dates);
console.log(end_dates);
console.log(start_times);
console.log(end_times);
// var params = "name="+name;"&department="+department;"&description="+description;"&fees="+fees;"&speaker="+speaker;"&no_of_days="+no_of_days;"&total_rows_of_dates="+total_rows_of_dates;"&start_dates="+start_dates;"&end_dates="+end_dates;"&start_times="+start_times;"&end_times="+end_times;
// event.preventDefault();
xhr= new XMLHttpRequest();
xhr.open('POST','http://localhost/sample_web/public/events',true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.onload=function(){
console.log(start_dates);
console.log(end_dates);
console.log(start_times);
console.log(end_times); }
// xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var params = {name:name, department: department, description: description, fees:fees, speaker:speaker, no_of_days:no_of_days, total_rows_of_dates:total_rows_of_dates, start_dates:start_dates, end_dates:end_dates, start_times:start_times, end_times:end_times};
xhr.send(JSON.stringify(params));
});