javascript - Ajaxform在提交之前获取数据被调用

标签 javascript jquery html ajaxform

我正在与 AjaxForm plugin 合作

我想提醒数据正在推送到服务器的内容。

<form class='frmAppList'>
    <input type='hidden' name='deviceid' value='<deviceId>'>
    <input type='hidden' name='operationtype' value='<Coming from server>'>
    <input type='hidden' name='type' value='command'>
    <button type="submit" class='btnAppsList button'>
         APPS LIST
    </button>
</form>

这是在jsp中循环的,因此表单会多次生成,具有class -> frmAppList .

我正在使用该类来应用ajaxform,如下所示:

$('.frmAppList').ajaxForm({
   url : 'urltoserver',
   dataType : 'json',
   type : 'post',
   beforeSubmit : function() {
     return false;
     //something here that gives me the device id that is passed
     //since the form is not one I cant use id, also every form has **deviceid**
     //i need to get that deviceid so that i can pass it in **success** ajax call
     //at ***Label->(A)*** 
   },
   success : function(response) {
      if (response.status) {
        //***Label*** ->(A)
        //have to call other ajax call to take the data 
        //for that i need the device id that is going in this ajax call
      }
   },
   error : function(xhr, ajaxOptions, thrownError) {
      alert('error');
   },
   timeout :10000
});

我怎样才能获得该设备ID,请帮助我.... 非常感谢......

最佳答案

来自 ajaxForm 文档:

success
Callback function to be invoked after the form has been submitted. If a 'success' callback function is provided it is invoked after the response has been returned from the server. It is passed the following arguments:
1.) responseText or responseXML value (depending on the value of the dataType option).
2.) statusText
3.) xhr (or the jQuery-wrapped form element if using jQuery < 1.4)
4.) jQuery-wrapped form element (or undefined if using jQuery < 1.4)
Default value: null

第三个和第四个参数就是您要寻找的。从这里开始:

success : function(response,status,request,form) {
  console.log(request,form);
}

关于javascript - Ajaxform在提交之前获取数据被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12707323/

相关文章:

javascript - 试图使下一个和上一个按钮出现在注册表单的不同时间

javascript - Angular 2 - 无法从 SignalR 范围访问组件成员/方法

javascript - D3 : How to add labels top of in each bar in grouped bar chart

html - 在 C 中解析 XML 和 HTML 的最佳且有效的方法

html - HTML 中的单词不断中断

javascript - js cookie 未显示在 chrome 开发人员工具中

c# - 如何获取通过Json获取的对象内部的值

javascript - 执行另一台服务器上的脚本

javascript - 如何在 JavaScript 中使用嵌套、揭示模块模式的链接?

javascript - 当我单击 md-select 时出现白色背景