尝试通过将ajax网址更改
url: "savedata.php",为,
url: "<?php echo admin_url('admin-ajax.php?action=save_order_data');?>"并在主题的function.php中添加以下代码
add_action('wp_ajax_nopriv_save_order_data', 'save_order_data');add_action('wp_ajax_save_order_data', 'save_order_data');function save_order_data() { global $wpdb; $total_amt = $_POST['amount']; $ship = $_POST['ship']; $token = $_POST['token']; $stmt = $wpdb->query("INSERT INTO order_master (payment_amt, ship, token) VALUES ('$total_amt', '$ship', '$token')" ); $result = $wpdb->query($wpdb->prepare($stmt)); if($result) { $res="Data Inserted Successfully:"; echo json_enpre($res); } else { $error="Not Inserted,Some Probelm occur."; echo json_enpre($error); }}
已更新:中 存在错误
var myKeyVals = { amount : <?php echo $total_amt; ?>., ship :<?php echo $ship; ?>., token : <?php echo $token; ?> }。
var myKeyVals如下更改您的:
var myKeyVals = { amount : "<?php echo $total_amt; ?>", ship : "<?php echo $ship; ?>", token : "<?php echo $token; ?>" }
您需要使用
""javascript编写php代码。
希望这可以帮助。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)