我想要一个正确的 ajax URL 这个不工作。我在控制台中得到这个:
GET XHR localhost:8000/Controller/getUnitSellingPrice [HTTP/1.0 404 Not Found 203ms]
create.blade View
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>
最佳答案
您应该向 web.php
文件添加一个路由。就像在您的 SalesController.php
在 SalesController 文件中:
public function getUnitSellingPrice()
{
/* your code */
}
在路由文件web.php
Route::any('sales-price/getunitsellingprice','SalesController@getUnitSellingPrice');
像这样更新您的 jquery URL:
url: '/sales-price/getunitsellingprice',
谢谢
关于javascript - Laravel 框架中 Controller 函数的 ajax url 不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58195746/