我想要一个正确的ajax URL,该URL无法正常工作。我在控制台中得到这个:
获取XHR本地主机:8000 / Controller / getUnitSellingPrice [HTTP / 1.0 404找不到203ms]
create.blade视图
C:\Apache24\htdocs\printshopsales\resources\views\sales\create.blade.php
Controller
C:\Apache24\htdocs\printshopsales\app\Http\Controllers\SalesController.php
我尝试过这里的内容:
<script>
$(document).ready(function() {
$("#stock_name").on('change', function () {
let element = $(this);
/*var MyAppUrlSettings = {
MyUsefulUrl : '/getUnitSellingPrice'
}*/
$.ajax({
//url: MyAppUrlSettings.MyUsefulUrl,
url: '/Controller/getUnitSellingPrice',
method: 'GET',
data: {
'stock_name' : element.val(),
},
success: function (response) {
$("#unit_selling_price").val(response.data).trigger('change');
console.log(response.data);
},
});
});
});
</script>
您应为此方法添加一条路线。就像您的SalesController.php
在SalesController文件中:
public function getUnitSellingPrice()
{
/* your code */
}
在路由文件中web.php
Route::any('sales/getunitsellingprice','SalesController@getUnitSellingPrice');
[更新您的jquery URL,例如:
url: '/sales/getunitsellingprice',
感谢