[英]My AJAX call only returns partial of my database and won't load more on scroll
[英]Why won't my AJAX call insert to the database?
我有一个ajax函数,用于在数据库中存储信息。 成功消息在控制台日志中消失,但实际上没有任何存储。 有任何想法吗?
如果要我打开错误消息,请告诉我确切的操作方法以及在哪个文件中。
AJAX(单击按钮即可关闭)
var id = ranNum;
//.cart-content is an item inside a shopping cart
$('.cart-content').each(function() {
//I know this is not the best way to grab data, but for now it's what I have to do
var item = $(this).find('.item').text();
var price = $(this).find('.price').text();
//These return the proper text, so I'm grabbing the information fine.
console.log("id: " + id);
console.log("item: " + item);
console.log("price: " + price);
$.ajax({
url : '../controllers/insertOrder.php',
//I even added extra letters just in case I couldn't use the same word twice.
data: {idd: id, itemm: item, pricee: price},
type : 'POST',
success : function(){console.log("success");},
error : errorHandler
});
});
insertOrder.php(路径正确)
<?php
require_once '../../models/database.php';
require_once 'Order.php';
$order = new Order;
$order->insertOrder($_POST['idd'], $_POST['itemm'], $_POST['pricee']);
Order.php
class Order{
public function __construct() {
}
public function insertOrder ($id, $item, $price) {
$db = Dbclass::getDB();
$query = "INSERT INTO orders (order_id, order_item, order_price)
VALUES(:id, :item, :price)";
$statement = $db->prepare($query);
$statement->bindParam(':id', $id, PDO::PARAM_INT, 11);
$statement->bindParam(':item', $item, PDO::PARAM_STR, 50);
$statement->bindParam(':price', $price, PDO::PARAM_STR, 10);
$statement->execute();
}
}
弄清楚了。 我的insertOrder.php文件中的数据库路径不正确。 天哪!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.