Reputation: 203
Update, I changed jQuery to this and it still doesn't work:
$("#click").click(function(){
$.post("accountcreation.php",function(response){ userCreation:"userCreation"
$("#justtesting").html(response);
})
})
Nothing is happening. I had the HTML and PHP working, but then I wanted to add live updating and began this jQuery code. What's wrong with it?
Thanks.
jQuery
$("#click").click(function(){
$.post("accountcreation.php", { userCreation:"userCreation"
})
$.get("accountcreation.php", function(data,status){
$("#justtesting").html(data);
})
})
HTML
Username: <input required type="text" name="userCreation"
onchange="userValidate();"
onkeypress="this.onchange();"
onpaste="this.onchange();"
oninput="this.onchange();">
<span id="userRegexJavascriptResponse"></span>
<br>
<input type="button" value="Submit" id="click">
<div id="justtesting"></div>
PHP (Part)
class accountcreation {
private $options;
function __construct($con, $ipCreation) {
$this->passwordCreation = $_POST['passwordCreation'];
$this->userCreation = $_POST['userCreation'];
$this->ipCreation = $ipCreation;
$this->emailCreation = $_POST['emailCreation'];
$this->con = $con;
}
Upvotes: 0
Views: 38
Reputation: 24638
Use this code instead. Your PHP script is expecting data via post, and you can get a response in that same .post()
call.
$("#click").click(function(){
$.post("accountcreation.php", { userCreation:"userCreation"}, function(data){
$("#justtesting").html(data);
});
});
NOTE: I would strongly advise against inline javascript
; it's so difficult to maintain and is just not good practice. Event listeners should be attached as above ... that's the way to go.
Your HTML should be:
Username: <input required type="text" name="userCreation">
<span id="userRegexJavascriptResponse"></span><br>
<input type="button" value="Submit" id="click">
<div id="justtesting"></div>
And, you do need to include jQuery core right before the JavaScript code:
<script src="//code.jquery.com/jquery-1.11.1.js"></script>
If you open your dev tools and run the code snippet below, you should see a post call being made with the data you supply. This means that it should be able to work on your server or else you should be able to see any errors in the console of the dev tools.
$("#click").click(function(){
$.post("accountcreation.php", { userCreation:"userCreation"}, function(data){
$("#justtesting").html(data);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Username: <input required type="text" name="userCreation">
<span id="userRegexJavascriptResponse"></span><br>
<input type="button" value="Submit" id="click">
<div id="justtesting"></div>
Upvotes: 1