douer9399 2010-09-22 16: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 16: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.

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

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)