If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

This all has primarily to do with what is known as scope in javascript and other programming languages. Making a separate version of everything is one way of dealing with the issue, but it is also usually the least efficient one.

You might not be ready for this yet, but you may, so have a look here:

It probably (with little or no modification) can handle all of your requests with little or no repetitious coding. It also is more robust, selecting the optimal request object for each browser, not just any that might be available, and covers more browsers. It also determines just once which request object that may be, instead of having to choose each time a request is made.

Though even that could be modularized instead of having to be repeated for each one. However, it's a good start. Before we worry about modularizing it further, we need to make sure we are passing the correct value of 'who' to the request. This (going by the earlier code you were showing):

Let's put it this way, I'm much better at javascript than I am at PHP. But this is still really mostly a question of javascript (about the 'who') only extremely basic PHP is involved. The PHP on writing.php is probably a bit beyond me or at the limits of what I can easily understand. The fact that you are passing writing.php a GET query value via javascript and AJAX though is not. It's obvious, to me at least, that the literal 'who' will not contain the value you want to send.

Now, it's not clear to me and I think you haven't shown/explained enough for me to know where the javascript value that should replace the literal 'who' will come from. But it has to come from somewhere. It can't always be the literal 'who', if it were, 'who' would always be writing and 'who' would be the only person who ever writes.

It would need to be (very loosely now, but still all javascript) something like:

Code:

function checkwhoiswriting(){
var who = something that is the value as a string;
new loadXmlHttp('writing.php?page=' + who, 'state');
setTimeout(checkwhoiswriting, 10000);
} ;
checkwhoiswriting();

Basically the only reason it is writing.php?page=who as opposed to writing.php is because I want to be able to have multiple things in one single PHP script. The literal value 'who' for the variable page IS what I want, and does return the data I want each time.

PHP Code:

if($_GET[page]=='who'){//LOOKUP PEOPLE WHO ARE WRITING FROM DB}

if($_GET[page]=='add'){//INSERT SOMEONE INTO THE DATABASE}

So essentially when the logged in user is typing into the message box (keyPress) a JS function is triggered which queries writing.php?page=add. I.E when a user is typing they are added to the database.

I then have another function checkwhoiswriting(); which gets a list of people already in the database.

So although they both query the same script, the data they return is different BECAUSE of the ?page=
Hope that makes sense, and that again I have understood what you are saying.

That actually makes sense, though as I imagined, it is at my limits of understanding as regards PHP. As long as it all works out, I'm not going to complain.

When I get more time, and if you are interested, I'll look into making this process (on the javascript side) more modular. At the very least, the more efficient setInterval can probably be used. But I'm still not sure whether or not I have enough information for more than that. If we get that far and I don't, I'll ask. However, just using the code we have been talking about so far (with the loadXmlHttp function) is a big improvement if it works out for you. Any questions on that, feel free to ask.