简体   繁体   English

发送字符串查询以及用户名和密码ajax

[英]send string query alongside user name and password ajax

I want to send command=login& string along side username and password collected from the form, like 我想将command=login&字符串以及从表单收集的用户名和密码一起发送

login.php?command=login&name=something&password=main

<form id="login" action="https//login.php" method="GET">
    <fieldset>
        <label for="name">Email</label>
        <input type="email" id="email" name="email">
    </fieldset>
    <fieldset>
        <label for="password">password</label>
        <input type="password" id="password" name="password">
    </fieldset>
    <fieldset>
        <input type="submit" value="Submit">
    </fieldset>
</form>


$('#login').on('click', function(e) {
    e.preventDefault();
    data: "command=login&" + ('#login').serialize(),
        $.get('https://login.php', data, function() {
            //  $('#').html(data);
        });
});

You can do: 你可以做:

  $.get('https://login.php?command=login&' + $('#login').serialize(), function() {
  //  $('#').html(data);
  });

Add a hidden input field to your form. 将一个隐藏的输入字段添加到您的窗体。 You should also be sending the form via POST and not GET since you are sending sensitive information. 您还应该通过POST而不是GET发送表单,因为您正在发送敏感信息。

<form id="login" action="https://login.php" method="POST">
    <input type="hidden" name="command" value="login">
    <fieldset>
        <label for="name">Email</label>
        <input type="email" id="email" name="email"  >
    </fieldset>
    <fieldset>
        <label for="password">password</label>
        <input type="password" id="password" name="password" >
    </fieldset>
    <fieldset>
        <input type="submit" value="Submit">
    </fieldset>
  </form>

Then remove the string portion from your data attribute like this: 然后像这样从您的data属性中删除字符串部分:

$('#login').on('click', function(e) {
  e.preventDefault();
  let data = $('#login').serialize()
  $.post('https://login.php', data, function(results) {
  //  $('#').html(results);
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM