Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. What you need in order to abstract the input from the input device is to have variables that store the value. Both the keyboard and mouse would manipulate the variables. You could rename the mouseX variable in that equation to something more meaningful and have both the mouse handler and the keyboard handler manipulate it. Since I don't have the specifications of your program I don't know exactly what exactly should go there.
  2. They ask the users for their location, I presume. I'm not on Facebook so I don't know. They can figure out the timezone from the geographical location. That would require a large database of locations and associated time zones.
  3. Where is the code that makes the mouse move the character. By setting the moveLeft and moveRight variables you should be able to move the character regardless of whether the keyboard or mouse changed them.
  4. That's not something most websites do. If you log out of the forum now you'll see that the post times are shown in UTC time. If you want to figure out a user's time offset you can try Geolocation or have Javascript send their local time so you can compare it to the server's time. You can check the offset in hours between the the client and the server and add that to the dates before showing them. Some time zones have half-hour offsets, so you would probably have to take that into account as well.
  5. Most systems give the user a dropdown with a list of time zones to choose from. The settings for the user are saved in a database. When the user is logged in, the user's settings are loaded from the database. Dates on the pages are shown in the user's timezone using methods such as DateTime::setTimeZone()
  6. While the closing ?> tag is not required for PHP to function, having it there should not actually change the functionality of the program either. I am completely confused as to what your server is doing.
  7. When you choose "Save as..." from the file make sure that you select "All files" instead of ".txt" in the save dialog. It would also be good to change the encoding dropdown to UTF-8, that's also in the save dialog. If you plan to write code frequently you should download a code editor such as Notepad++.
  8. How about if you put the file right at the root of the website? Directly at http://localhost:8888/test2.php
  9. It sounds like the CSS for the label is to blame.
  10. The text-shadow property in CSS will do that as long as you don't set a blur radius.
  11. That definitely would cause a Not Found error. What program are you using to edit PHP files?
  12. The Javascript is working as it is supposed to. The server just seems to not be executing the PHP code. I can't think of any reason why it's not working. Try making a new PHP file test2.php in the same directory and open it in the browser. Make it simple: <?php echo 'Hello, World!'; ?>
  13. I'm not sure if this is the one you're using, but this URL won't work: file: // localhost/Applications/MAMP/htdocs/test-site/wp-content/my-php-files/test.php You need to use http://localhost to make the PHP run.
  14. Unfortunately nothing's showing up in your posts. The file does have a .php extension so I don't know why the PHP isn't being parsed. Is this the URL you're using in your Javascript code? http://localhost:8888/test-site/wp-content/my-php-files/test.php
  15. No, Wordpress doesn't have anything to do with it unless you're actually loading Wordpress code inside test.php What is the complete URL in the browser 's address bar when you open test.php?
  16. This is a problem. PHP isn't being parsed. Your server is just sending the code straight to the browser without running it. What the browser should get when you open that page is a number, not PHP code.
  17. Javascript is working exactly as it should. It sounds like PHP is not being parsed. Open test.php right in your browser and press Control+U to see actual the source code.
  18. Is that what you see when you open test.php in your browser?
  19. First of all, it means that setRequestHeader() has to be called after .open() Are you loading this page on your localhost or are you just double-clicking it in your filesystem? AJAX on your desktop can't read PHP on localhost. Make sure your HTML page is also being executed on localhost. If that's not the mistake, then the port number of your HTML page and of the PHP file you're trying to request are probably different. Either remove the port number from the URL or make sure they're both the same.
  20. Your jsfiddle example isn't doing anything so I can't test your code. If you want to prevent it from going further than a particular point, then in the drag event handler have an if() statement that compares the position of the object to the limits you don't want it to pass. You should know how to get the position of the element. The Max and min limits depend on the width and height of the parent element, the minimum limits are probably just zero. if(xPosition > xMaxLimit) xPosition = xMaxLimit;if(xPosition < xMinLimit) xPosition = xMinLimit;if(yPosition > yMaxLimit) yPosition = yMaxLimit;if(yPosition < yMinLimit) yPosition = yMinLimit;
  21. That code should work. Keep the HTML as I showed it, the HTML is fine. Check your Javascript. Open the Javascript console in your browser's developer tools to check for errors. Check the Network tab in the developer tools to see the AJAX request and the response from the server.
  22. The <body> element should be the parent of all other elements except the <head>. Your HTML neesd to be valid if you want Javascript and CSS to work properly. To know if your HTML is valid, pass your code through the validator: http://validator.w3.org/ This is how a website structure should be: <!DOCTYPE html><html> <head> <title>AJAX request</title> <script type="text/javascript" src="http://localhost:8888/.../test.js"></script> </head> <body onload="ajax_post()"> <div id="demo"></div> </body></html> The <!DOCTYPE> declaration tells the browser what language and version the page is using. The <html> element is the root of the entire website. The <head> element contains information about the page. The <body> element contains the content of the page.
  23. I think you need to fix your HTML. The <body> element cannot be inside any other element except the <html> element. Pass your code through the HTML validator. Since the <div id="demo"> is outside the <body> element, it doesn't exist when the body has loaded.
  24. If absolutely nothing is appearing in the console that means the request isn't being sent. One thing that might be interfering is that your <input> element is a submit button. If you have an actual form in your code with a real submit button then the event handler should go right on the <form> element instead of the button: <form method="POST" onsubmit="ajax_post(); return false"> If there is no <form> then change your <input> to type="button".
×
×
  • Create New...