Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8934573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:49:18+00:00 2026-06-15T09:49:18+00:00

I am creating a blackjack game using html, js, ajax and php. When the

  • 0

I am creating a blackjack game using html, js, ajax and php. When the Player first loads the game, a prompt appears on the page asking for the name, and this goes to a name.php which checks to see if the user name is in the database. If not, it adds it. In either case, it will place the player’s name and bank total on the screen. This part of my code was working fine until I added the next part of the code.

When the user clicks on the “hit” button, hit.php is called, which for now should just be pulling 1 card from the deck table (will fully implement hit later on) and placing it within the “player” div on the screen. However, now that I have 2 ajax calls, nothing whatsoever is happening, including the original prompt for the player name.

Is the 2nd call somehow interfering with the 1st call?

Any suggestions as to how I should treat the ajax calls would be greatly appreciated.

var username;
var playerName = "";
var playerBank = 0;
var playerCard;
var playerHandValue = 0;
var dealerHandValue = 0;
var randomCardNumber;

function checkName() {
username = prompt("Welcome to Blackjack.\n Please enter your username");
if(document.getElementById('playerName').value == null) {
    ajaxName();
}   
click();
}

function printName() {
return playerName;
}

function printBank() {
return playerBank;
}
function ajaxName() {
var uName = username;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttpN=new XMLHttpRequest(); 
} 
else {// code for IE6, IE5 
    xmlhttpN=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
xmlhttpN.onreadystatechange=function() { 
    if (xmlhttpN.readyState==4 && xmlhttpN.status==200) { 
        var elements = xmlhttpN.responseText.split("|");
        playerName = elements[0];

        playerBank = elements[1];
        document.getElementById('playerName').innerHTML = printName();
        alert(playerName);
        document.getElementById('playerBank').innerHTML = printBank();

    }
} 
xmlhttpN.open("POST","name.php",true); 
xmlhttpN.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttpN.send("player="+username);
}
function click() {
document.getElementById('hit').onclick = function(){ ajaxButton(this);};
document.getElementById('stand').onclick = function(){ ajaxButton(this);};
document.getElementById('raiseBet').onclick = function(){ ajaxButton(this);};
document.getElementById('newGame').onclick = function(){ ajaxButton(this);};
}
function ajaxButton(buttonClicked) {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari 
    xmlhttpB=new XMLHttpRequest(); 
} 
else {// code for IE6, IE5 
    xmlhttpB=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
xmlhttp.onreadystatechange=function() { 
    if (xmlhttpB.readyState==4 && xmlhttpB.status==200) { 
        var elements = xmlhttpB.responseText;
        if(buttonClicked.innerHTML == "HIT") {
            randomCardNumber = randNumber(1,52);
            playerCard = elements[0];
            document.getElementById('player').innerHTML = displayCard();
            xmlhttpB.open("POST","hit.php",true); 
            xmlhttpB.setRequestHeader('Content-type','application/x-www-form-urlencoded');
            xmlhttpB.send("card_id="+randomCardNumber);
        }
    }
if(buttonClicked.innerHTML == "STAND") {
    alert("stand");
}
if(buttonClicked.innerHTML == "RAISE BET") {
    alert("raise bet");
}
if(buttonClicked.innerHTML == "NEW GAME") {
    alert("new game");
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:49:19+00:00Added an answer on June 15, 2026 at 9:49 am

    No JavaScript errors reported in your browser, and the prompt isn’t coming up at all, and nothing happens when you click hit? It sounds as though perhaps you aren’t calling the checkName() or click() functions at all. Have you refactored those into methods recently when they weren’t previously?

    It seems to me that checkName should occur as soon as the page loads, so if it doesn’t already, try putting a call to it in a script block at the bottom of the page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating a simple RPG game, first time using XNA. Trying to get my character
I am creating a card game (blackJack) in android. the first two cards are
I'm creating a card game with multiple classes. Currently, I'm using global variables to
Creating my WordPress author.php template page and ran into a little roadblock. I want
I'm creating a simple black jack game using the Easy 68K simulator and need
thanks for reading this. I'm creating just a simple, generic version of blackjack using
Creating a website using simple html(not html5) and css but got stock in mouseover
Creating a pacman-like game, where a player eats objects. When a MovieClip (box) eats
For a programming class I am creating a blackjack program for the first homework
Error creating bean with name 'sessionFactory' defined in class path resource [ApplicationContext.xml]: Invocation of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.