Php 使用jquery通过AJAX嵌套JSON数据,但得到未定义的值

Php 使用jquery通过AJAX嵌套JSON数据,但得到未定义的值,php,jquery,arrays,json,ajax,Php,Jquery,Arrays,Json,Ajax,我收到一条错误消息。 未捕获引用错误:未定义产品 $(document).ready(function(){ $("div").on("click", "a", function(){ var delivery_id = $(this).attr("id"); $.ajax({ url:"http://localhost:8888/dashboard/fetch_edit.php", method:"POST

我收到一条错误消息。 未捕获引用错误:未定义产品

$(document).ready(function(){
    $("div").on("click", "a", function(){
        var delivery_id = $(this).attr("id");
        $.ajax({
            url:"http://localhost:8888/dashboard/fetch_edit.php",
            method:"POST",
            data:{products:products},}
        });
    });
JSON


您正在尝试引用一个不存在的属性

假设您将JSON对象分配给一个变量,如下所示:

obj = {
  .... the JSON
}
然后可以按如下方式传递JSON

data:{products:obj.products}
希望这对你有帮助

var products_obj = '{ "id": "2", "send_id": "10", "tracking_id": "TI-000000010", "user_id": "10", "username": "istiaqahmed", "email": "istiaqahmed121998@gmail.com", "phone": "0176430886", "company_name": "EVALY.COM.BD", "company_phone": "01747588386", "company_address": "Dhanmondi 28", "com_email": "evaly@gmail.com", "delivery_type": "Standard", "packing": "regular", "product_weight": "1", "preferred_time": "morning", "delivery_charge": "60", "customer_name": "Zenith Jhony", "to_address1": "75\/1 Jafrabad Pulpar Pabna House Goli", "to_phone": "01776065208", "to_zone": "Dhaka", "to_post_code": "1207", "date": "2020-01-09 23:26:10", "u_status": "Approve", "notes": "note", "products": [ { "product_id": "1", "product_name": "shampoo", "product_quantity": "2", "product_price": "2333", "customer_send_id": "10" }, { "product_id": "2", "product_name": "assf", "product_quantity": "1", "product_price": "232", "customer_send_id": "10" } ] }';
products_obj = JSON.parse(products_obj);
var products= products_obj.products;
console.log(products);

$(document).ready(function(){
    $("div").on("click", "a", function(){
        var delivery_id = $(this).attr("id");
        $.ajax({
            url:"http://localhost:8888/dashboard/fetch_edit.php",
            method:"POST",
            data:{products:products},}
        });
});

首先,在这里添加代码,直接添加图像,而不是作为链接。这需要更多的信息,也有类似的问题,由于缓存,插件etcI添加了我的代码
var products_obj = '{ "id": "2", "send_id": "10", "tracking_id": "TI-000000010", "user_id": "10", "username": "istiaqahmed", "email": "istiaqahmed121998@gmail.com", "phone": "0176430886", "company_name": "EVALY.COM.BD", "company_phone": "01747588386", "company_address": "Dhanmondi 28", "com_email": "evaly@gmail.com", "delivery_type": "Standard", "packing": "regular", "product_weight": "1", "preferred_time": "morning", "delivery_charge": "60", "customer_name": "Zenith Jhony", "to_address1": "75\/1 Jafrabad Pulpar Pabna House Goli", "to_phone": "01776065208", "to_zone": "Dhaka", "to_post_code": "1207", "date": "2020-01-09 23:26:10", "u_status": "Approve", "notes": "note", "products": [ { "product_id": "1", "product_name": "shampoo", "product_quantity": "2", "product_price": "2333", "customer_send_id": "10" }, { "product_id": "2", "product_name": "assf", "product_quantity": "1", "product_price": "232", "customer_send_id": "10" } ] }';
products_obj = JSON.parse(products_obj);
var products= products_obj.products;
console.log(products);

$(document).ready(function(){
    $("div").on("click", "a", function(){
        var delivery_id = $(this).attr("id");
        $.ajax({
            url:"http://localhost:8888/dashboard/fetch_edit.php",
            method:"POST",
            data:{products:products},}
        });
});