使用 jQuery 将多维数组发送到 php
嘿,我这里有一个小大问题:)
在我上传一些图像后,我得到了一个包含所有图像的列表。我有一些用于旋转、复制、删除、随机播放图像的 jQuery 函数!当我选择一个图像并点击删除时,我会向 php 发送一个带有图像的 alt=""
值的帖子,我会识别该图片并进行编辑。
我想做一个保存按钮 与其每次旋转图像时都发送帖子,不如在使用包含所有数据的数组编辑图像列表后发送帖子?
上传后我的 php 数组如下所示:
[files] => Array
(
[lcxkijgr] => lcxkijgr.jpg
[xcewxpfv] => xcewxpfv.jpg
[rtiurwxf] => rtiurwxf.jpg
[gsbxdsdc] => gsbxdsdc.jpg
)
假设我上传了 4 张图片,
- 第一张图片我旋转 90 度,
- 第二张图片我想复制,
- 第三张图片我旋转 270 度
- ,第四张图片我删除,
我只能使用 jQuery 来完成这一切,但是在服务器图像是相同的,刷新后图像是相同的,
这是包含图像的列表:
<div class="upimage">
<ul id="upimagesQueue">
<li id="upimagesHPVEJM">
<a href="javascript:jQuery('#upimagesHPVEJM').showlargeimage('HPVEJM')">
<img alt="lcxkijgr" src="uploads/s6id9r9icnp8q9102h8md9kfd7/lcxkijgr.jpg?1272087830477" id="HPVEJM" style="display: block;" >
</a>
</li>
<li id="upimagesSTCSAV">
<a href="javascript:jQuery('#upimagesSTCSAV').showlargeimage('STCSAV')">
<img alt="xcewxpfv" src="uploads/s6id9r9icnp8q9102h8md9kfd7/xcewxpfv.jpg?1272087831360" id="STCSAV" style="display: block;" >
</a>
</li>
<li id="upimagesBFPUEQ">
<a href="javascript:jQuery('#upimagesBFPUEQ').showlargeimage('BFPUEQ')">
<img alt="rtiurwxf" src="uploads/s6id9r9icnp8q9102h8md9kfd7/rtiurwxf.jpg?1272087832162" id="BFPUEQ" style="display: block;" >
</a>
</li>
<li id="upimagesRKXNSV">
<a href="javascript:jQuery('#upimagesRKXNSV').showlargeimage('RKXNSV')">
<img alt="gsbxdsdc" src="uploads/s6id9r9icnp8q9102h8md9kfd7/gsbxdsdc.jpg?1272087832957" id="RKXNSV" style="display: block;">
</a>
</li>
<ul>
</div>
如果我制作一个像这样的数组,可以吗
array{
imgFromLi = array(img1,img2,img3,img4,img5,img6)
rotate = array{img1=90, img2=270, img3=90}
delete = array{img4,img5,img6}
duplicate = array{img2, img3}
}
我如何制作/发送/缓存该数组?
抱歉我的英语很差
编辑:
是的,我使用 json 从 php 接收数组,如下所示:
jQuery.post(script, postData, function(data) {
if(data){
jQuery("#upimagesQueue").text(' ');
jQuery.each(data, function(ID, val) {
jQuery("#upimagesQueue").listimages(ID, val);
});
}
}, "json");
hy, i have a little, big problem here :)
after i upload some images i get a list with all the images. I have some jQuery function for rotate, duplicate, delete, shuffle images! when i select a image and hit delete i send a post to php with the alt=""
value of the image,i identify the picture and edit.
I want to make a save button,
Instead of sending a post every time i rotate a image, better send a post after editing the list of images with an array that contains all data?
my php array after upload looks like this:
[files] => Array
(
[lcxkijgr] => lcxkijgr.jpg
[xcewxpfv] => xcewxpfv.jpg
[rtiurwxf] => rtiurwxf.jpg
[gsbxdsdc] => gsbxdsdc.jpg
)
say that I uploaded 4 pictures,
- firs picture i rotate 90 degrees
- second i want to duplicate
- third i rotate 270 degrees
- and the fourth image i delete
i can do all this only with jQuery, but on the server the images are the same, after a refresh the images are the same
this is the list with the images:
<div class="upimage">
<ul id="upimagesQueue">
<li id="upimagesHPVEJM">
<a href="javascript:jQuery('#upimagesHPVEJM').showlargeimage('HPVEJM')">
<img alt="lcxkijgr" src="uploads/s6id9r9icnp8q9102h8md9kfd7/lcxkijgr.jpg?1272087830477" id="HPVEJM" style="display: block;" >
</a>
</li>
<li id="upimagesSTCSAV">
<a href="javascript:jQuery('#upimagesSTCSAV').showlargeimage('STCSAV')">
<img alt="xcewxpfv" src="uploads/s6id9r9icnp8q9102h8md9kfd7/xcewxpfv.jpg?1272087831360" id="STCSAV" style="display: block;" >
</a>
</li>
<li id="upimagesBFPUEQ">
<a href="javascript:jQuery('#upimagesBFPUEQ').showlargeimage('BFPUEQ')">
<img alt="rtiurwxf" src="uploads/s6id9r9icnp8q9102h8md9kfd7/rtiurwxf.jpg?1272087832162" id="BFPUEQ" style="display: block;" >
</a>
</li>
<li id="upimagesRKXNSV">
<a href="javascript:jQuery('#upimagesRKXNSV').showlargeimage('RKXNSV')">
<img alt="gsbxdsdc" src="uploads/s6id9r9icnp8q9102h8md9kfd7/gsbxdsdc.jpg?1272087832957" id="RKXNSV" style="display: block;">
</a>
</li>
<ul>
</div>
is ok if i make one array like this
array{
imgFromLi = array(img1,img2,img3,img4,img5,img6)
rotate = array{img1=90, img2=270, img3=90}
delete = array{img4,img5,img6}
duplicate = array{img2, img3}
}
how i can make/send/cache this array??
sorry for my very bad english
Edit:
Yes i use jSON to recive the array from php like this:
jQuery.post(script, postData, function(data) {
if(data){
jQuery("#upimagesQueue").text(' ');
jQuery.each(data, function(ID, val) {
jQuery("#upimagesQueue").listimages(ID, val);
});
}
}, "json");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许如果您使用 JSON 您的代码会更简单,并且更容易立即发现任何问题。
Maybe if you use JSON your code will be simpler, and will be easier to spot any problems right away.