开发者

Rely on javascript to execute PHP script or manipulate hidden form elements and rely on PHP?

开发者 https://www.devze.com 2023-01-05 05:16 出处:网络
I wrote a JavaScript script that swaps two selected img tag src values. The point is to let the user rearrange a list of images.

I wrote a JavaScript script that swaps two selected img tag src values.

The point is to let the user rearrange a list of images.

For sending the new order to a PHP script, I have two ideas:

  1. Have a button execute a JavaScript function that gathers the new order of images into an array of URLs. Then, rely on JavaScript to send the 开发者_如何学编程data to a PHP script?

  2. Have the initial JavaScript rearrange hidden input tag value attributes which would contain data such as a URL and order number. Then, rely on a submit input button to execute a POST request without JavaScript?

Thanks!


Why not consider using Jquery's UI Draggable/Sortable? It takes some of the brain damage out of the code and gives the user an intuitive way to interface with the reordering process:

http://jqueryui.com/demos/draggable/#sortable

You could then use the callbacks to update via Ajax, or set variables that could be dumped to PHP on submit.

0

精彩评论

暂无评论...
验证码 换一张
取 消