PHP loop won't wait for user to click button. I am considering writing all code in Javascript

jquery

#1

I'm making my own quiz on a website and so far have learned heaps.
However, I'm having trouble incorporating the user input from their choice of buttons into my PHP script.
I have been told that PHP won't wait for the JQuery events.
So now I am considering rewriting the array and logic part of the code in Javascript.
Unless someone knows an easier alternative.
I read somewhere about doing an AJAX call, but that sounds complicated.

It has taken me a few weeks to learn PHP and get the script working, so I'm not keen to discard it.
However, Javascript doesn't seem much different from PHP in syntax.

If I am faced with the choice of rewriting in Javascript or adding AJAX, would either choice be more suitable for a site that is being used by many people simultaneously?

I would appreciate any helpful suggestions.

You can see my progress live.
http://www.fastenglish.net/Vocab1.php

The PHP code is attached.
Vocab1.php (2.7 KB)


#2

I haven't looked at your code, but since PHP runs on the server it doesn't know or care what the user is doing.

If you want interaction from users then you're either going to need to use AJAX or do the job in JavaScript.


#3

Yes, so which method would be able to handle more simultaneous users more easily, the AJAX/JQuery/PHP method, or the JQuery/Javascript method?


#4

In the beginning of the year I wrote a Trivia game in pure javascript and here's a link to all the important files in my Github repository. You'll still be using Ajax even if you use JQuery, but using JQuery Ajax is a little easier to understand. I like using vanilla javascript for it easily transported without having to install the JQuery Library and you'll really aren't writing that much more code. I'm going to be rewriting this game again to use JSON instead of XML using vanilla javascript and to get rid of .innerHTML. I have a jquery quiz version in my github Repositories somewhere that could also help you.


#5

I am currently using PHP arrays, so I could easily convert them to Javascript arrays.
Hence I wouldn't need to access any database.
So why would I need to use AJAX if I wrote it all in Javascript?

I'm wondering if I could just use the PHP BREAK command or EXIT at the JQuery part, but I don't know how I would get the loop to restart.


#6

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.