I am trying to run a PHP script as soon as Submit button is clicked. I wanted to do an AJAX call as i dint want to refresh the page after the button is clicked. But the below code is not responding upon click.

我在点击“提交”按钮时尝试运行PHP脚本。我想做一个AJAX调用,因为我想点击按钮后刷新页面。但是下面的代码没有响应点击。

I have saved the login.php in the same location as my project. Any help or input is appreciated!

我已将login.php保存在与项目相同的位置。任何帮助或输入表示赞赏!

<input type="button" class="button" value="submit" />
<script type="text/javascript">
$(document).ready(function() {
    $("button").click(function() {
        $.ajax({
            type: "GET",
            url: "C:\wamp\www\ElitePass\login.php"
        })
        alert("done successully")
    });
});
</script>

2 个解决方案

#1


2

The issue is that you are not targeting your button correctly.

问题是您没有正确定位按钮。

$("button") this selector is looking for an element of type "button". Naturally there is none. To target elements by their class names, append dot to selector:

$(“按钮”)此选择器正在查找“按钮”类型的元素。当然没有。要按类名称来定位元素,请将点附加到选择器:

$(".button").click(....)

Having said that, your code will still not work as you expect it to. Browser security restrictions will prevent loading of files directly from your file system. You need to load stuff via web server. Especially PHP files.

话虽如此,您的代码仍然无法按预期工作。浏览器安全限制将阻止直接从文件系统加载文件。您需要通过Web服务器加载东西。特别是PHP文件。

更多相关文章

  1. 由于底层异常,无法加载连接类:'java.lang.NumberFormatException:对
  2. 加载数据INFILE不工作。
  3. JSON保存在数据库中并使用JQuery加载
  4. zTree.js 异步加载地区例子
  5. 加载外部站点并更改其可视化
  6. js点击button按钮跳转到另一个新页面
  7. Emberjs应用程序加载除Index之外的所有路由
  8. javascript阻塞加载问题【转】
  9. 我可以禁用“后退”按钮浏览器功能吗?

随机推荐

  1. ajax的xmlHttpRequest对象
  2. Java&Xml教程(七)使用JDOM修改XML文件内容
  3. 疯狂XML学习笔记(11)-----------XSLT讲解
  4. Java&Xml教程(六)使用JDOM解析XML文件
  5. 疯狂XML学习笔记(10)---------XML的作用
  6. Java&Xml教程(五)使用SAX方式解析XML文件
  7. 疯狂XML学习笔记(9)-------------Schema内
  8. Java&Xml教程(四)使用DOM方式生成XML文件
  9. 疯狂XML学习笔记(8)---------schema 的简单
  10. Java&Xml教程(三)使用DOM方式修改XML文件内