Published:
September 18, 2019Ajax call using jquery
function makeAjaxRequest(data1,data2,.....,datax){ $.ajax({ 'type':'POST', async: false, url: 'http://www.example.com/some_request_url', data:{param1:data1,param2:data2,....,paramx:datax}, success : function(response) { console.log(response); // Using this you can check the posted data in browser console window return true;// you can process and return the response as required //location.reload(); // or you may reload the current page also }, error: function (jqXHR, exception) { // If some error is returned, you can check the details below var msg = ''; if (jqXHR.status === 0) { msg = 'Not connect.\n Verify Network.'; } else if (jqXHR.status == 404) { msg = 'Requested page not found. [404]'; } else if (jqXHR.status == 500) { msg = 'Internal Server Error [500].'; } else if (exception === 'parsererror') { msg = 'Requested JSON parse failed.'; } else if (exception === 'timeout') { msg = 'Time out error.'; } else if (exception === 'abort') { msg = 'Ajax request aborted.'; } else { msg = 'Uncaught Error.\n' + jqXHR.responseText; } $('#post').html(msg); // return the error response in your html page or process it further as required } }); }