weixin_33749131 2012-06-06 18:02 采纳率: 0%
浏览 23

在表格中实现ajax保存

I'm implementing a virtual tour application, and want to add ajax functionality to the tour build process.

I have a number of mini-forms on the page, the number of which is determined by the count of images in a specified directory.

So the page currently looks like

---------------------------------------------------
|             |           Location   
|             |           Latitude
|  Thumb      |           Longitude       --------
|             |                           | Save |
|--------------                           --------
|
---------------------------------------------------
---------------------------------------------------
|             |           Location   
|             |           Latitude
|  Thumb      |           Longitude       --------
|             |                           | Save |
|--------------                           --------
|
---------------------------------------------------
---------------------------------------------------
|             |           Location   
|             |           Latitude
|  Thumb      |           Longitude       --------
|             |                           | Save |
|--------------                           --------
|
---------------------------------------------------

and goes on for n number of images.

What I'd like to do is have the save button execute an ajax function to save the information without refreshing the page. My issue has to do with the button IDs. As the form is rendered via PHP echo statements in a loop, I can add the loop number to the button ID, but how can I use said ID in a jquery function?

Specifically,

$("#save").click(function(){
  //ajax POST code goes here
});

won't work when the #save has a number added to the end.

What other options do I have to implement ajax functionality to these forms?

  • 写回答

2条回答 默认 最新

  • weixin_33701251 2012-06-06 18:13
    关注

    I would add a class to each button then attach the click event to that class and then find the ID that way. Then you can run your AJAX.

    Like this:

    $('.buttonClass').click(function (){
        var id = this.id;
        var $thisButton = $('#' + id);
        //Can do jQuery stuff with $thisButton now
        //Run AJAX
    });
    

    Just make sure you add the class to every save button.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?