dougutuo9879 2016-10-07 03:46
浏览 32
已采纳

PHP AJAX - <input>元素可以像<form>一样具有“action”吗?

Forms have an action attribute to specify where (for example a .php file) to post to. Do <input> elements have the action attribute?

  1. The answer is most likely no. But I wish to know what concept am I getting wrong here?
  2. Is there a equivalent of action for <input>?
  3. The reason I am asking this is that I have a few checkboxes, and I wish to use AJAX to fire something to a PHP file, such that a div changes when the checkboxes are ticked (I don't want a whole page reload). How should I go about doing this?

I am still drafting the code at this stage, but an example can be seen here.

Appreciate your suggestions!

  • 写回答

3条回答 默认 最新

  • duanhong8839 2016-10-07 04:06
    关注

    Based on comments it really sounds like you want something to be sent when any number of checkboxes might be changed.

    Add an event handler to all of them, serialize() the form and post it whenever any one of them changes

    var $form =$('#myForm'); 
    $form.find(':checkbox').change(function(){
         var formData = $form.serialize();
         $.post('/someFile.php', formData, function(response){
             // do something with response
         }).fail(function(){
             alert("Oops something bad happened');
         });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题