2016-09-14 141 views
-1

我有一个webform(如下),我想将表单变量传递给函数。将形式变量传递给参数

我想一旦用户点击提交的用户名和密码被传递到一个网站登录功能:

$.ajax({ 
      url: "http://microsubs.risk.net/microsub.php", 
      method: 'GET', 
      success: function (data) { 
       if (data == 1) {$('#rdm-below-header').append('<div id=\"modal\" class=\"modalStyle\">' + 

         '<div>' + 

         '<button type=\"button\" id=\"close\" class=\"close\" data-dismiss=\"modal\" aria-label=\"close\"><span aria-hidden=\"true\">&times;</span></button><br>' + 

          '<div id=\"titleText\" style=\" text-align:center; font-size: 24px; margin-top: 15px;\">Fill in your details for 24hr access to Risk.net</div><br>' + 


         '<form id=\"microsubs_form\" style=\"text-align:center; clear:both\" >' + 

          '<input type=\"text\" id=\"ms_firstName\" name=\"ms_firstName\" required placeholder=\"First Name\" style=\"float:left;\" >' + 

          '<input type=\"text\" id=\"ms_lastName\" name=\"ms_lastName\" required style=\"float:left; margin-left:20px;\" placeholder=\"Last Name\">' + 

          '<input type=\"email\" id=\"ms_email\" name=\"ms_email\" required placeholder=\"Corporate Email address\" pattern=\"^.*(\*barclays|\*barcap).*$\" oninvalid=\"this.setCustomValidity(\'Please enter your corporate email\')\" style=\"float:left; margin-top: 10px;\">' + 

          '<input type=\"password\" id=\"ms_password\" name=\"ms_password\" required style=\"clear:right; margin-top: 10px; margin-left: 20px;\" placeholder=\"Password\" pattern=\".{6,}\">' + 

          '<input class=\"cls_redirect\" id=\"redirect_url\" name=\"redirect_url\" type=\"hidden\" value=\"http://www.risk-responsive.nginx.incbase.net/\">' + 



          '<input type=\"submit\" id=\"submit-form\" class=\"btn.login\" name=\"submit\" style=\"alignment-adjust:central; margin-top:30px; clear:right;\" ><br>' + 

         '</form>' + 



         '<div style=\"text-align:center; clear: both; font-size: 16px; margin-top: 5px; \"><br>' + 

          'If you already have a subscription, <a href=\"login\">sign in here.</a>' + 



         '</div>' + 

        '</div>' + 

        '</div>'); 
       } 
        console.log(data); 
       $('#submit-form').on('click', function(){ 
        formSubmit(); 
       }) 


      }, 

      error: function(error) { 
       console.log(error); 
      } 

     }); 


// Bind to the submit event of our form 


function formSubmit(){ 
    $("#microsubs_form").submit(function(event){ 

var request; 

// 
var userName = ms_email; 
var userPwd = ms_password; 

    // Abort any pending request 
    if (request) { 
     request.abort(); 
    } 
    // setup some local variables 
    var $form = $(this); 

    // Let's select and cache all the fields 
    var $inputs = $form.find("input, select, button, textarea"); 

    // Serialize the data in the form 
    var serializedData = $form.serialize(); 


    // Disabled form elements will not be serialized. 
    $inputs.prop("disabled", true); 

    // Fire off the request to /form.php 
    request = $.ajax({ 
     url: "http://microsubs.risk.net/ms_form_handler.php", 
     type: "POST", 
     data: serializedData, 
     success: function(data){ 
      console.log(data); 
      $("#rdm-below-header").hide(); 

      siteLogin(userName, userPwd, 'http://www.risk-responsive.nginx.incbase.net/') 
     }, 
     error: function(error) { 
       console.log(error); 
      }, 
    }); 

    // Prevent default posting of form 
    event.preventDefault(); 
}); 

在阿贾克斯有成功:

**siteLogin(username here, password here, 'http://www.risk-responsive.nginx.incbase.net/')** 

的用户名和密码用户在表单中创建的内容应该放在这里。

我尝试添加它象下面这样:

var userName = ms_email; 
    var userPwd = ms_password; 

但是这是行不通的,所以任何的帮助深表感谢。

+0

没有ü尝试'变种的userName = $( '#ms_email')VAL()'? – naortor

回答

0

您需要添加它们是这样的:

var userName = ms_email.value; 
var userPwd = ms_password.value;