Once you get the response you can decide if it is an error or success. Using jquery you can then target and append to the list or error div. example
If(data.error == 1) {
$('div.alert').append('error message');
} else {
$('div.list ul').append('success message');
}
Hey alnutile,
Thank you for taking your time to reply to me.
Am I missing something here? (It just shows me my JSON output on submit for both success and false):
<script>
$('form#ajaxcreate').on('submit',function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
cache: false,
dataType: 'JSON',
url: '/admin/products/create',
data: $('form#ajaxcreate').serialize(),
success: function(data) {
If(data.error == true) {
$('div.alert').append('error message');
} else {
$('div.list ul').append('success message');
}
},
});
return false;
});
</script>
I would do it this way :
Load the list template without any data (optionally with data) then call a function to fetch json and populate the list.
Now, when the user creates a new row :
if request was a success, call the function we called on-load.
if request failed, show an error
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community