我试图获得所有的表格数据在AAL人选择国家,然后收集select.when表格数据和存储在一个变量中,
<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>这是我的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);
}
});
}
});这是我尝试发送所有表单数据时的控制器
public function avatax(Request $request){
$data=$request->all();
print_r($data);
die();
$tb = new Avalara\TransactionBuilder($client, "AGELESSZENINC", Avalara\DocumentType::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>');
}
}发布于 2019-11-29 16:14:33
我还是不知道你的问题。如果您希望获得表单中的所有数据并在ajax中使用,您可以查看我的代码:
<script type="text/javascript">
$('#country').change(function(){
let formData = $('#formid').serialize();
var cid = $(this).val();
if(cid){
$.ajax({
type:"get",
url:" {{url('/ava')}}/",
data: formData,
success:function(res)
{
alert(res);
}
});
}
});您可以在https://api.jquery.com/serialize/中看到serialize()。有什么我可以帮您的吗。使用post方法:
<script type="text/javascript">
$('#country').change(function(){
let formData = $('#formid').serialize();
var cid = $(this).val();
if(cid){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type:"post",
url:" {{url('/ava')}}/",
data: formData,
success:function(res)
{
alert(res);
}
});
}
});发布于 2019-11-29 16:21:11
首先,您应该使用serialize()方法来实现您的目标。此方法将序列化整个窗体,并将其赋给任何变量。下面是我的post方法示例:
$('#country').on('change', function() {
const formData = $('#formid').serialize();
console.log(formData);
$.ajax({
type: "post",
data: formData,
url: " {{url('/ava')}}/",
success: function(res) {
alert(res);
}
});
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form 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>
<option value="us">USA</option>
<option value="canada">Canada</option>
<option value="brazil">Brazil</option>
</select>
</form>
发布于 2019-11-29 16:17:51
<script type="text/javascript">
$('document').ready(function(){
alert();
$('#country').change(function(){
var cid = $('#country').val();
alert(cid);
$.ajax({
url: 'www.example.com/page.php',
method:"post",
data:{'country', cid},
success:function(res)
{
alert(res);
}
});
});
});
</script>在page.php中,您需要像这样获取varible。回显$_POST‘’country‘;
https://stackoverflow.com/questions/59100948
复制相似问题