0

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;
    }
9
  • 2
    there is no event onClick in jquery. api.jquery.com/click Commented Oct 21, 2014 at 22:47
  • I changed it to "click," I still get no result. Commented Oct 21, 2014 at 22:52
  • You should be receiving the data in the post success handler. Commented Oct 21, 2014 at 22:52
  • @showdev I updated the script, no joy yet. Commented Oct 21, 2014 at 22:59
  • 1
    Here's a demo. Commented Oct 21, 2014 at 23:30

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

6 Comments

This doesn't do anything, either. Is the click function wrong, perhaps? It's supposed to mate with this: <input type="button" value="Submit" id="click">
i.imgur.com/H5csicO.jpg and i.imgur.com/Up1Wqy6.jpg <-- Still, nothing happens...
@icor103 Check your browser console for javascript errors. It looks like you've got some HTML (a <div>) inside your <script></script> tags.
@showdev .. That's embarassing, thank you. I would use console, but I can never get the dang thing to work very well. Is there a browser/plugin that you suggest?
@icor103 I've gotten used to Firebug. But most modern browsers have some equivalent.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.