I want a correct ajax URL this one is not working. I am getting this in the console:
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
I have tried what is here:
<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>
You should add a route to web.php
file. Like in your SalesController.php
In SalesController file:
public function getUnitSellingPrice()
{
/* your code */
}
In Route file web.php
Route::any('sales-price/getunitsellingprice','SalesController@getUnitSellingPrice');
Update your jquery URL like:
url: '/sales-price/getunitsellingprice',
Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.