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

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -