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.
I have saved the login.php in the same location as my project. Any help or input is appreciated!
<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>
-
Do you see any error in console? Is the request hit to the server?Tushar– Tushar2015年07月23日 05:44:16 +00:00Commented Jul 23, 2015 at 5:44
-
The request is not going to $("button").click(function() itself. Still unable to figure out howGoutam– Goutam2015年07月23日 05:53:10 +00:00Commented Jul 23, 2015 at 5:53
2 Answers 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.
2 Comments
You can call success like :
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$.ajax({
type: "GET",
url: "C:\wamp\www\ElitePass\login.php",
success: function() {
alert("done successully");
}
})
});
});
</script>
1 Comment
But the below code is not responding upon click.
Does this mean that even alert
is not displayed