weixin_33737774 2019-03-18 15:04 采纳率: 0%
浏览 31

JavaScript行为不当

I am trying to send my form data to an .php file with AJAX but JS is misbehaving , what actually happens is that when i leave the input fields empty every thing works fine (i.e. the php program executes and make changes in my database as expected) but when i fill form data , like when i fill name , email ,password my client side page refreshes and php file dosent gets executed .

Sorry for any grammatical mistakes .

I appreciate any help from anyone !

Thanks alot !

var form = document.getElementById("form_signup");
var formdata = new FormData(form);

$('#form_signup').on('submit', function(ev) {
  console.log(formdata);
  ev.preventDefault();
  $.ajax({
    url: "./process_php/Signup1.php",
    data: $('form').serialize(),
    cache: false,
    processData: false,
    contentType: false,
    type: "POST",


    success: function(response) {
      console.log("done" + response);
    }

  });
  return false;

});
<?php 
if (!isset($_REQUEST['username'])) {
    die();
}
$username = "temp_username";
$email = "temp_email";
$password = "temp_password";
$sqlconnection = new mysqli("", "", "", "");
$insertstatement = "INSERT INTO new_users (Name , Email , Password , Subscriber ) VALUES ('$username' , '$email' , '$password' , 'Normal' ) ";
if ($sqlconnection->query($insertstatement) === TRUE) {                      //if entered into db successfully
    echo "DONE";
}else {

    //run js to inform
    }

?>
<!--I have loaded jquery and also my external js file-->

<form class="font1" id="form_signup">
  <!-- main content , signup form -->
  <h2 id="form_name" class="font1">LOGIN</h2>
  <input type="text" name="username" placeholder="Username" minlength="3" autofocus id="username"><br>
  <input type="email" name="email" placeholder="Email" minlength="10"><br>
  <input type="password" name="pass" placeholder="Password" minlength="8"><br>
  <input type="submit" value="Confirm">
</form>

</div>
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Android URL如何转成视频/音频,可行吗?
      • ¥20 SQL数据查询,子查询
      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 vue+uniapp
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题