-1
我一直在关注一个CRUD教程,位于这里https://www.codeofaninja.com/2015/06/php-crud-with-ajax-and-oop.html。 我可以创造更新和删除,但在阿贾克斯成功火灾我得到一个错误:ajax成功后我打电话给showProducts()
showProducts() not defined
这样的产品列表不会刷新。我不明白如何在没有某种引用类型的情况下找到showProducts()
。我知道showProducts()
的作品,因为它被称为在$(document).ready(function()
{
// show list of product on first load
showProducts();
});
works fine.
// send delete request to api/remote server
$.ajax({
url: "http://localhost/api/product/delete.php",
type : "POST",
dataType : 'json',
data : JSON.stringify({ id: product_id }),
success : function(result) {
// re-load list of products
showProducts();
},
error: function(xhr, resp, text) {
console.log(xhr, resp, text);
}
});
}
是你的ajax和showProducts函数在同一个上下文中吗? – Roljhon
“showProducts()”如何定义?你在定义之前调用它吗?在AJAX请求之前找到调用它的简单方法,以确保不会造成范围问题 – santi6291
read-products.js是showProducts()的定义。 read-products.js位于index.php
因为您的
showProducts()
函数未定义只需创建($ Ajax调用)之前之一,它添加一些数据,例如:
你想要把你的数据在HTML DIV:
和你提到的教程他们的链接添加这些内容:
来源
2017-03-12 19:02:45
的路径确定如果我把函数放在.ajax代码的前面,它会很好。现在我必须复制确切的代码并将其粘贴到以下文件 create-products.js,edit-products.js,delete.js这看起来像我在3个不同的位置复制代码。 我以为代码需要一个路径的功能showProducts() 像'read-products.js - > showProducts();' –