I have form which sends array of objects in json format using ajax. But when I do $request->getContent I only get the token. It seems I don't even send data, could you help me?
my form in createPage.blade.php
<form action="/invoices/submitInvoice" method="post" id="my-form">
HERE IS MY TABLE STRUCTURE CODE
<button type="submit">Send</button>
</form>
<button onclick="myCreateFunction()">Add</button>
my sending logic in sendGood.js
let counter = 0,
nameContainer = [],
priceContainer = [],
obj = {},
objArr = [];
$(function(){
$('#my-form').submit(function(e){
let elements = document.querySelectorAll("#my-form input[type=text]");
//Just loop over inputs and gather values
for (let i = 0, element; element = elements[i++];) {
if(element.type === "text"){
if(element.value){
if(element.className === "goodName")
nameContainer.push(element.value);
else
priceContainer.push(element.value);
}
}
}
//Push to object array that going to be sent via ajax
for(let i = 0; i < nameContainer.length; i++){
obj.name = nameContainer[i];
obj.price = priceContainer[i];
objArr.push(obj);
obj = {};
}
let route = $('#my-form').data('route');
$.ajax({
type : 'POST',
url : url('/invoices/submitInvoice'),
data : {dataInput : JSON.stringify(objArr)},
contentType: 'application/json; charset=utf-8',
dataType : 'json',
success: function(Response){
console.log("daw",Response);
}
});
e.preventDefault()
});
});
InvoiceControllerWeb.php
public function invoiceCreate(Request $request){
dd($request->all());
}
Result
^ array:1 [▼
"_token" => "hEfjKsDHZadG3G5fCIgEJWcrNrFpv6G4PtjUPzJA"
]
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OD4ixB
via IFTTT
Aucun commentaire:
Enregistrer un commentaire