weixin_33725272 2017-11-06 11:21 采纳率: 0%
浏览 32

未通过AJAX调用PHP文件

Below is my code for the problem. I am trying to call php file via AJAX. I have an HTML file where after form submission, the AJAX calls the PHP file. Unfortunately, I cannot see any output.

HTML File(Body):

<form>
  <label for="">Username</label>
  <input type="text" name="username" value="">
  <br><br>
  <label for="">Password</label>
  <input type="text" name="password" value="">
  <br>
  <button name="button" id="button" value="Submit">Submit</button>
</form>
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<script src="login.js"></script>

My login.js file(for AJAX):

$("#button").click(function(e){
e.preventDefault();

$.ajax({
 type: 'POST',
 url: 'login.php'
 });
});

My PHP file:

<?php
 // Server credentials
 $serverName = "localhost";
 $username = "root";
 $password = "root";
 $dbName = "Blog";

 //Creating connection
 $db = mysqli_connect($serverName,$username,$password,$dbName);
 if(!$db){
   echo "error";
   die($db);
 }

 else{
   echo "er22ror";
 }

 mysqli_close($db);
?>
  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题
      • ¥15 win11如何运行geoserver
      • ¥15 审稿意见请教-用ERNIE进行小样本分类的对比实验问题
      • ¥15 gem5搭建arm v8