douer9399 2010-09-22 08:00
浏览 21
已采纳

在cakephp中将数据从javascript传递给PHP

Hello I have a select element which has a few options. I am able to get the selected option when an onChange event is fired. Now I need to pass that option text to php, either with pageload or ajax.

echo $form->select('data_source_select',$dataSourceOptions,null,array('escape'=>false, 'empty'=>'Select One','onChange'=>'getData(this)'));

is my select form element, with its options being set in controller. Now onchange, I need to pass the selected option to php/action to load the data specific to this option search. Any help would be great.

Thanks.

  • 写回答

1条回答 默认 最新

  • dongwei2030 2010-09-22 08:47
    关注

    As you said, you could either do this as a regular form submission, or as an Ajax form submission. My answer will focus on regular form submission, since Ajax will essentially work the same way and can simply be added on to enhance it later.

    One quick solution is to add a hidden field to your form, maybe call it "step" and give it a value of 1. When the data source is selected, simply submit the form and check the value of "step" in your controller. If it is equal to 1, you'll know to load the data based on data_source_select. If the value of "step" is not 1, it indicates that you're on another step in the process and you don't need to process the data source value again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部