Reputation:
I'm trying to insert the modal values by serializing those form values and trying to insert into it. But it's not working.
SCRIPT CODE:
<script type="text/javascript">
$(document).ready(function () {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$("#priceSave").click(function(e){
e.preventDefault();
//var form1=$("#formprice").serialize();
var data = $('form').serialize();
$.ajax({
url:'addPriceDetails/{{$dataId}}',
type: "post",
data: data,
dataType: 'json',
success: function(response) {
alert(response.SKUID);
/*$("#skuid").append(response.SKUID);
$("#mrp").append(response.MRP);
$("#lstatus").append(response.listingStatus);
$("#selprice").append(response.sellingPrice);*/
//alert(response.SKUID);
}
});
});
$("#descSave").click(function(e){
e.preventDefault();
var form2=$("#formdescription").serialize();
//var data = $('form').serialize();
$.ajax({
url:'addPriceDetails/{{$dataId}}',
type: "post",
data: form2,
dataType: 'json',
success: function(response) {
alert(response);
}
});
});
});
</script>
This is what I have tried.But I have some doubts with the commented lines.
Controller code:
public function addPriceDetails(Request $formprice,$dataId)
{
$priceInfo = new priceModel ;
$priceInfo->deviceCategoryId=$dataId;
$priceInfo->productId=$this->getproductId();
$priceInfo->SKUID=$formprice->input('skuid');
$priceInfo->listingStatus =$formprice->input('listingStatus');
$priceInfo->MRP =$formprice->input('mrp');
$priceInfo->sellingPrice=$formprice->input('selprice');
$priceInfo->fulfillmentBy =$formprice->input('fulfillment');
$priceInfo->procurementType =$formprice->input('procurementType');
$priceInfo->procurementSLA =$formprice->input('sla');
$priceInfo->stock =$formprice->input('stock');
$priceInfo->localDelCharge =$formprice->input('local');
$priceInfo->zonalDelCharge =$formprice->input('zonal');
$priceInfo->nationalDelCharge=$formprice->input('national');
$priceInfo->packWeight =$formprice->input('weight');
$priceInfo->packLength =$formprice->input('length');
$priceInfo->packBreadth =$formprice->input('breadth');
$priceInfo->packHeight =$formprice->input('height');
$priceInfo->HSN =$formprice->input('hsn');
$priceInfo->save();
$description=new descriptionModel;
$description->deviceCategoryId=$dataId;
$description->productDescriptionId=$this->getproductDescriptionId();
$description->modelName=$formdescription->input('mname');
$description->Height=$formdescription->input('height');
$description->Weight=$formdescription->input('weight');
$description->Depth=$formdescription->input('depth');
$description->Width =$formdescription->input('width');
$description->Type =$formdescription->input('type');
$description->Character=$formdescription->input('character');
$description->batteryType=$formdescription->input('batteryType');
$description->salesPackage =$formdescription->input('package');
$description->skillSet =$formdescription->input('skillSet');
$description->Colour=$formdescription->input('colour');
$description->Material =$formdescription->input('material');
$description->maxAge=$formdescription->input('maxage');
$description->minAge =$formdescription->input('minage');
$description->batteryNos =$formdescription->input('batteryNos');
$description->batteryOperated=$formdescription-
>input('batteryOperated');
$description->rechargable=$formdescription->input('rechargable');
$description->save();
return response()->json([
'SKUID' => $priceInfo->SKUID,
]);
}
This is my controller code.Here I am trying to get the form values from both the modals.
Upvotes: 1
Views: 120
Reputation: 2466
Do these changes first -
id
selector to your form.<form name='formprice' id='formPrice'>
<form name="formdescription" id="formdescription">
type="submit"
to type="button"
3.In your ajax call user your id selector to serialize the form.
var form1 = $('#formPrice').serialize();
var form2=$("#formdescription").serialize();
Upvotes: 1