Support the ongoing development of Laravel.io →
posted 9 years ago
Views Forms
Last updated 2 years ago.
0

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');
}
Last updated 2 years ago.
0

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>
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Reached reached Joined 27 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.