• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript JQuery JSON updating sql

I am trying to update an league table with game scores. On game start 0-0, games played, games drawn and pts won increase 1 for both teams. After a team scores, one team's draw becomes a win and gets 2 more points, goals for increases by 1, the other team's draw becomes a loss and loses a point, goals against increases by 1. I am trying to send the teams and scores to php for processing.

This is my code:
As far as dataType seems to be working. Any help appreciated.

JSON:
document.getElementById("Home1Goals").innerText = 0;
    document.getElementById("Away1Goals").innerText = 0;
    $(document).on("click", "#Week1Game1Start", function() {
        $.ajax({
                method: "POST",
                url:    "Operations.php",
                data: {"Week1Game1Home": "Home1Goals", "Week1Game1Away": "Away1Goals"},
                dataType:"json",
                
                success: function(data)
                {
                    var result = JSON.parse(data);
                    alert(parsedJSON.canApprove);
                    if(data.statusCode==200)
                    {
                        alert('success');
                                            
                    }
                }
                });


            });
 
I should make a macro for this because I must have said it 5 billion times. Jquery without the HTML is worthless,

But what you did give us says you are sending data that you don't define. Where are Home1Goals and Away1Goals defined?
As of jQuery 3.0, $.parseJSON is deprecated. Note the dollar sign and dot preface.
Where do you post this on the site?
 
I should make a macro for this because I must have said it 5 billion times. Jquery without the HTML is worthless,

But what you did give us says you are sending data that you don't define. Where are Home1Goals and Away1Goals defined?
As of jQuery 3.0, $.parseJSON is deprecated. Note the dollar sign and dot preface.
Where do you post this on the site?
The data are the names of html data cells containing team names and goals scored by each team.

HTML:
<td style="width: 200px; text-align: center;" name="Week1Game1Home" >Home Team</td>
<td name="Home1Goals" id="Home1Goals" style="width: 20px;"></td>
<td name="Away1Goals" id="Away1Goals" style="width: 20px;"></td>
<td style="width: 200px; text-align: center;" name="Week1Game1Away">Away Team</td>
 
I should make a macro for this because I must have said it 5 billion times. Jquery without the HTML is worthless,

But what you did give us says you are sending data that you don't define. Where are Home1Goals and Away1Goals defined?
As of jQuery 3.0, $.parseJSON is deprecated. Note the dollar sign and dot preface.
Where do you post this on the site?
With some help I got the JQuery/JSON working to the extent the call is failing. I'm using wamp (localhost). As all the files I'm using are in the same folder, is the php file name enough for the url?
 
The data are the names of html data cells containing team names and goals scored by each team.
Why would you do that? I can't think of one instance when a PHP script would use that information sent to it nor use it.

With some help I got the JQuery/JSON working
For the life of me, I can't see that happening with the code you posted. Why not show the new code. I'm interested in how Jq is placing the returned info to the DIVs.
 

New Threads

Latest posts

Buy us a coffee!

300x250
Top Bottom