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;
    }
icor103
  • 193
  • 1
  • 8

1 Answers1

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>
PeterKA
  • 24,158
  • 5
  • 26
  • 48
  • This doesn't do anything, either. Is the click function wrong, perhaps? It's supposed to mate with this: `` – icor103 Oct 21 '14 at 23:10
  • http://i.imgur.com/H5csicO.jpg and http://i.imgur.com/Up1Wqy6.jpg <-- Still, nothing happens... – icor103 Oct 21 '14 at 23:23
  • 1
    @icor103 Check your browser console for javascript errors. It looks like you've got some HTML (a `
    `) inside your `` tags.
    – showdev Oct 21 '14 at 23:25
  • @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 Oct 21 '14 at 23:30
  • @icor103 I've gotten used to [Firebug](http://getfirebug.com/). But most [modern browsers](https://developer.chrome.com/devtools/docs/console) have [some equivalent](https://developer.apple.com/safari/tools/). – showdev Oct 21 '14 at 23:33
  • @showdev Firebug is the one I tried first, it always gave me no data at all.. Maybe the version I'm using is all screwed up. – icor103 Oct 21 '14 at 23:34