javascript - How to call an exception with post method (AJAX)? -


if post method unsuccessful want throw exception , write error log? if method returns no results want throw exception , write file.

post method:

$.post("ip.php", function( data ){ $("#ip").val(data.ip); $("#country").val(data.country); $('#campaignid').val(data.campaignid); }, "json"); 

for part of question:

if post method unsuccessful want throw exception (...)

you chain .fail() callback method $.post() request mentioned @grimbode

or use $.ajax() instead, error option - function called if request fails.
$.ajax() equivalent $.post() method be:

$.ajax({     type     : "post",     url      : "ip.php",     datatype : 'json',     success  : function(data){         $("#ip").val(data.ip);         $("#country").val(data.country);         $('#campaignid').val(data.campaignid);     },     error   : function(jqxhr/*object*/, textstatus/*string*/, errorthrown/*object*/){         // throw error ...         // console.log('type of error: ' + textstatus);     }, }); 

as part:

(...) write error log

it's not possible write file javascript. since it's client side scripting language executes in client browser, has no access server. well, that's how works.


Comments

Popular posts from this blog

c# - ItextSharp font color issue in ver 5.5.4+ -

jquery - Multiple issues with pushstate: history, loading, calling functions -

ios - retrievePeripherals deprecated in IOS7 how to substitude it with retrievePeripheralsWithIdentifiers -