What this is supposed to do is call the actions.php, and then return the an array of the 'POST'as 'GET' type Here is the code. I can get the alert("Not in the ajax") to respond, but anything inside the $.ajax
does not: are there any suggestions?
/******This is the jquery and ajax files***********************/
/****************************
$("#loginSignupButton").click(function() {
// alert("Not in the ajax");
$.ajax({
type: "POST",
url: "actions.php?action=loginSignup",
data: "email=" + $("#email").val() + "&password" + $("#password").val() + "&loginActive=" + $("#loginAcive").val(),
success: function( result ) {
alert(result);
}
})
})
/********************************/
/**** on the actions.php file this is the code:****/
include("functions.php");
if ($_GET['action'] == "loginSignup") {
print_r($_POST);
}
/**************************/
Typically when you click on a button it has a default action that you can prevent with
$("#loginSignupButton").click(function(event) {
event.preventDefault()
//call ajax stuff here
}
In your case you aren't capturing the event because your callback does not have any input parameters. Also a POST typically sends something to the server, if you expect to get something back, that would go inside your success callback, in this case, you are simply displaying that as an alert, and that is all that I would expect to see in this case.
Please note that Method: POST sends some serializable data to the server while a GET would request something from the server. It's hard to understand exactly what you are trying to do.
Sidenote: You can also use 'this' keyword as well such as:
$("#loginSignupButton").click(function() {
this.preventDefault()
}
Which you may see in the future, but don't worry about it as its not prudent to understanding AJAX requests
I think that your resource is not returning success code, that's why your success function is never executed.
To find out if that is true, add below lines to your code:
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus);
}
You can read more about using jQuery.ajax
in jQuery docs.
Make sure the button is actually being clicked (maybe your id is wrong?)
$("#loginSignupButton").click(function() {
alert('working')
Then add this under success:
error: function(e) {
console.log(e)
}
Open up your console (F12) and take a look to see if there is an error output.
While you are in your console, look at the Network tab. Is there being a request sent? What are the parameters? What is the response?
Also note an event listener like this cannot be set until after the DOM has loaded, so you need to wrap it with $(document).ready(function(){ ... }
So it turns out the bootstrap ajax link I was using apparently is or was not working this link:
How ever when I changed the ajax to google it worked: