我有一个AJAX调用来获取模型中的记录,并在GET请求完成后必须弹出的模式中显示值。
javascript控制台正在返回Uncaught ReferenceError: KWS1389776 is not defined at HTMLButtonElement.onclick
在onClick事件中如何将变量传递给javascript函数看起来有些问题。
这是开发的代码:
<button type="button" class="btn btn-label-primary btn-lg btn-upper"
data-toggle="modal" data-target="#kt_modal_4_2"
onClick="getPropertyDetails({{$match->prop_id}})">
{{ __('pages/processes/offerdemand.labels.matchs.index.button.viewproperty') }}</button><?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Property;
class PropertyController extends Controller
{
public function details($id)
{
$property = Property::where('prop_id', $id)->first();
return view('pages.processes.offerdemand.matchs.propertymodal', compact('property'));
}
}function getPropertyDetails(prop_id) {
console.log(prop_id);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
method: 'GET',
url: '/property/details/' + prop_id,
success: function (data) {
console.log(data);
if (data.status != 200) {
console.log(data.status);
swal.fire({
"title": "",
"text": "Ocurrió un error, contactar al administrador",
"type": "error",
showConfirmButton: !1,
timer: 3000,
onClose: () => {
window.location.reload();
}
});
}
$('#kt_modal_4_2').modal("show");
}
});
}发布于 2020-03-27 03:08:18
问题是你给它传递了一个变量,不是吗?
您需要将输入包装为字符串,例如
onClick="getPropertyDetails('{{ $match->prop_id }}')">此时,我只能假设您的prop_id为KWS1389776,并且出现错误是因为作为变量的引用不存在,正如错误所述。
https://stackoverflow.com/questions/60873873
复制相似问题