weixin_33725270 2010-05-04 13:38 采纳率: 0%
浏览 41

jQuery Ajax:动态功能

I am trying to write a function which allows me to perform an ajax call dynamically, but am unsure how to make the key which is passed to the ajax call dynamic...

At the moment, my code is like this

$('#ajaxButton').click(function(){
    var form = $(this).parent().find(':input');
    var formVal = form.val();
    var objectName = form.attr('id');

    submitAjaxForm(formVal,objectName);

});    

function submitAjaxForm(formVal,objectName){
     data = {
             objectName : formVal
            }
     // Ajax Call
     $.post('handlers/' & objectName & '.cfc?method=save',data,function(){
           }
     });

Essentially, what I am trying to do, is pass a form fields value to a function that will process it, and then dynamically set the data key, and the handler.

Now I can dynamically set the handler using the objectName vaidable...but when I try and use this variable to set the data key, it doesnt like it..

I hope this makes sense..

Any ideas?

Thanks

  • 写回答

3条回答 默认 最新

  • 衫裤跑路 2010-05-04 13:41
    关注

    Try using + rather than & when trying to stick your objectName in your url string.

    $.post('handlers/' + objectName + '.cfc?method=save',data,function(){});
    

    Also try doing this to set the value of data:

    var data = {};
    data[objectName] = formVal;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题