jquery - Ajax call successful, but not appearing in network panel -
i've implemented ajax call in js on wordpress front-end page. ajax call successful (sucess() called, , see 200 response on complete()), ajax call not appear in network panel within chrome. it's understanding, based on working ajax calls in past, call should appear in network panel within chrome further inspection. i'm looking in xhr subsection of network panel, , see no calls being made. have, however, looked in 'all' section of network panel verify call never showing in network panel @ all. i'm curious why be.
here's js:
jquery(document).ready(function() { jquery.ajax({ datatype: 'json', method: 'post', url: "<?php echo admin_url('admin-ajax.php'); ?>", data: {action: 'myaction'} }) .success(function(data) { console.log( "success " + data); }) .fail(function() { console.log( "error" ); }) .complete(function(xhr, textstatus) { console.log(xhr.status); }) .always(function() { console.log( "complete" ); }); }
my console logs following output:
success 0 complete 200
it's hitting success, getting 200 response, , not failing. shouldn't show in network panel?
i'am not sure if related or not while ago had same problem. request returning zero, happens when try call wp-ajax action isn't registered. have managed wp-ajax calls before didn't know why time wasn't working. think because ajax call data type json. stumbled upon example data parameter formdata object:
var data = new formdata(); data.append('action', 'your_action'); data.append('somedata', somedata); $.ajax({ method: "post", url: "<?php echo esc_url(admin_url('admin-ajax.php')); ?>", processdata: false, contenttype: false, cache: false, data: data, datatype: "json", success: function(response, textstatus, jqxhr) { if (response.status === "ok") { // success } else { console.log('status: ' + response.status); } }, error: function(jqxhr, textstatus, errorthrown) { console.log("error: " + textstatus); console.log(errorthrown); }, complete: function(jqxhr, textstatus, errorthrown) { } });
if has better knowledge please explain why works.
i hope helps you.
Comments
Post a Comment