duandui5648 2014-10-17 15:46
浏览 32

使用不带形式的多个diemnstion数组运行jquery ajax

I am trying to scrap some elements data from a page using jquery and sending to a php file to save in database what i am doing is:

  1. I am creating two dimensional array and want to pass data to php file so I can run a foreach load to save in database:

Error: Now getting the message : SyntaxError: Unexpected token A in alert box which is alert(errorThrown);

my jquery code is:

            function scrape() {

                var info = new Array();
                $("div.clip").each(function (index) {

                    info[index] = {};
                    info[index]['name'] = $(this).find(".fn").text();
                    info[index]['rating'] = $(this).find("span.tinyPush").text();
                    info[index]['review'] = $(this).find("p.description").text();

                });
                console.log(info);
                $.ajax({
                    type: "POST",
                    url: "save_scrap.php",
                    data: {info: info},
                    dataType: "json",
                    beforeSend: function () {
                        // Do something before sending request to server
                    },
                    error: function (jqXHR, textStatus, errorThrown) {

                        alert(errorThrown);
                    },
                    success: function (data) {
                        console.log(data);
                        $("#div1").html(data);
                        alert('success!');
                    }
                });
            return false;
        }

and i am trying to get it in php file as :

print_r($_POST) ;

please let me know in comments if you think question is not good or not explaining well.

Thanks.

  • 写回答

1条回答 默认 最新

  • doudou8783 2014-10-17 15:48
    关注

    var info = new Array(); needs to be

    var info = []; and it should also be outside the .each scope.

    评论

报告相同问题?

悬赏问题

  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题