I am trying to get All form data on select.when someone select country ,then collect aal form data and store in a variable,
<from name="form1" id="formid">
<input type="text" name="address">
<input type="text" name="pincode">
<input type="hidden" name="price" value="80">
<select class="form-control" name="country" id="country">
<option value="">Select Country</option>
@foreach ($countries as $country)
<option value="{{$country->id}}">
{{$country->name}}
</option>
@endforeach
</select>
</from>
Here Is my ajax.
<script type="text/javascript">
$('#country').change(function(){
var cid = $(this).val();
if(cid){
$.ajax({
type:"get",
url:" {{url('/ava')}}/"+cid,
success:function(res)
{
alert(res);
}
});
}
});
Here Is my controller When I am trying to send all form data
public function avatax(Request $request){
$data=$request->all();
print_r($data);
die();
$tb = new AvalaraTransactionBuilder($client, "AGELESSZENINC", AvalaraDocumentType::C_SALESINVOICE, 'ABC');
$t = $tb->withAddress('SingleLocation', '123 Main Street',null,null, 'Irvine', $id, '92615', 'US')
->withLine(100.0, 1, null, "P0000000")
->create();
echo('<h2>Transaction #1</h2>');
echo('<pre>' . json_encode($t, JSON_PRETTY_PRINT) . '</pre>');
}
}
3
Answers
I still don’t know your problem. If you want to get all data in form and use in ajax, you can see my code:
You can see
serialize()
in https://api.jquery.com/serialize/. May I help you.With post method:
in page.php you need to get varible like this.
echo $_POST[‘country’];
Well, first of all you should use serialize() method to achieve your goal. This method will serialize your entire form and will assign it to any variable. Here my example with post method: