dopuzf0898 2014-02-18 16:21
浏览 46
已采纳

Javascript数组转换为jQuery.post的数据

I am trying to send different values to php script using jQuery.post

The data I want to send are links like this

http://example.com/image1.jpg
http://example.com/image2.jpg
http://example.com/image3.jpg
http://example.com/image4.jpg

I don't have an exact amount of these links they would vary depending on the user interacting with my script

I am storing these links in a javascript array "fileLinks".

what I want to do is to send these links to php using jQuery.post

Can I format these links in this shape?

jQuery.post(MyAjax.ajaxurl,
            { action : 'ajax-rform',
              link1: http://example.com/image1.jpg,
              link2: http://example.com/image2.jpg,
              link3: http://example.com/image3.jpg,
              link4: http://example.com/image4.jpg,
            },
            function(data){
                jQuery("#fileupload").after('<h1>Success</h1><p>Your registration has been recieved.</p>');
            }
           );

In php I just need to use for loop and replace the link1 and http://example.com/image1.jpg with the arrays and php would iterate it for me but what should I do in javascript?

Thanks

  • 写回答

3条回答 默认 最新

  • drzdu44226 2014-02-18 16:28
    关注

    Just pass the array. jQuery will encode it with array notation, and PHP will decide it back into an array:

    jQuery.post(MyAjax.ajaxurl,
                { action : 'ajax-rform',
                  link: fileLinks
                },
                function(data){
                    jQuery("#fileupload").after('<h1>Success</h1><p>Your registration has been recieved.</p>');
                });
    

    In PHP, you can access the array as $_POST['link'].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?