I want to know how can I show popup message after user changed field and updated data by AJAX?
here is my code:
public function UpdateorderbuyerByAjax(Request $request)
{
try {
$id = $request->input('pk');
$field = $request->input('name');
$value = $request->input('value');
$order = Order::findOrFail($id);
$order->{$field} = $value;
$order->save();
} catch (Exception $e) {
return response($e->getMessage(), 400);
}
return response('', 200);
}
PS: Using Laravel 5
.
update
my full java script code, i need to show custom message to user only when he/she changed // buyer update
part.
<script type="text/javascript">
$(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
// buyer update
$('.user').editable({
source: [
@foreach($users as $user)
{ value: '{{ $user->id }}', text: '{{ $user->name }}' }
@unless ($loop->last)
,
@endunless
@endforeach
]
});
// update status
$(function() {
$('.status').editable({
source: [
@foreach($orderstatuses as $status)
{ value: '{{ $status->id }}', text: '{{ $status->title }}' }
@unless ($loop->last)
,
@endunless
@endforeach
]
});
});
// transaction code
product_id = $(this).data('pk');
url = $(this).data('url');
$('.transaction').editable({
url: url,
pk: product_id,
type:"text",
validate:function(value){
if($.trim(value) === '')
{
return 'This field is required';
}
}
});
});
</script>
UPDATE 2
my latest code
<script type="text/javascript">
$(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function (response) {
alert(
'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Numquam eius odio eum soluta atque voluptatibus ducimus, debitis corrupti! Enim pariatur voluptates, dolor doloremque dignissimos cum amet veritatis deleniti voluptatibus sunt!'
);
}
});
// buyer update
$('.user').editable({
source: [
@foreach($users as $user)
{ value: '{{ $user->id }}', text: '{{ $user->name }}' }
@unless ($loop->last)
,
@endunless
@endforeach
]
});
// update status
$(function() {
$('.status').editable({
source: [
@foreach($orderstatuses as $status)
{ value: '{{ $status->id }}', text: '{{ $status->title }}' }
@unless ($loop->last)
,
@endunless
@endforeach
]
});
});
// transaction code
product_id = $(this).data('pk');
url = $(this).data('url');
$('.transaction').editable({
url: url,
pk: product_id,
type:"text",
validate:function(value){
if($.trim(value) === '')
{
return 'This field is required';
}
}
});
});
</script>