Created
October 18, 2016 08:59
-
-
Save arnaimbd/559904e080bdef103c6b75a0fdc57d7c to your computer and use it in GitHub Desktop.
Debuging ajax call on WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( "wp_ajax_stock_form", function() { | |
if ( !isset( $_POST['data'] ) ) { | |
wp_send_json_error( ['msg' => 'Wrong data'] ); | |
} | |
$args = []; | |
wp_parse_str( $_POST['data'], $args ); | |
$id = $_POST['warehouse_id']; | |
file_put_contents( __DIR__ . "/debug.txt", print_r( $args, 1 ) ); | |
wp_send_json_success( $data ); | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function($) { | |
$('#stockForm').on("submit", function(e) { | |
e.preventDefault(); | |
// console.log( $(this).data("warehouse-id") ); | |
$.post( | |
wc_add_to_cart_params.ajax_url, | |
{ | |
action: "stock_form", | |
data: $(this).serialize(), | |
warehouse_id: $(this).data("warehouse-id"), | |
} | |
).done(function(res) { | |
console.log(res); | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment