07-17-2009, 03:18 PM
I'm building this rather complex order entering system, and I need to build a bunch of different AJAX scripts to do essentially the same thing, just calling to different PHP scripts depending on what is changing. I'm new to this and I'm not sure on the best way to set this up.
which is the better option?
1. saving a separate .js file for each different script.
2. or is there a way to combine them all and just have on .js file called on the page?
Thank you for your help!
07-17-2009, 04:11 PM
You can combine all the functions into one single .js file. There is no virtue in having multiple .js files.
Remember that there must be no duplicaton of function or variable names.
All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
07-17-2009, 04:22 PM
ok, here's the script that I have right now. The two parts highlighted in RED are what will change, the PHP file just contains the MySQL query and the formatting for the results. The ID is attached to the DIV tag that will have the replaced data.
alert ("Browser does not support HTTP Request");
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
I'm assuming that what I need to have unique between the two functions is what I changed to the GREEN text. the stateChanged function being called in the updateStock function. both containing unique information. So, as long as the Green and red items are unique, I can just repeat the two functions in the same script.
Is that right? sorry to be a pain, but I think I jumped in a bit over my head and I'm trying to do this all correctly so that I can easily change things down the road.
07-17-2009, 04:41 PM
You can combine all the functions into one single .js file. There is no virtue in having multiple .js files. ...and by reducing the number of linked files, you can reduce the the number of server requests.
07-17-2009, 04:46 PM
...and by reducing the number of linked files, you can reduce the the number of server requests.
that's what I thought, but I wasn't 100% sure on how to repeat the function without running into an issue.
Thanks both of you for your help!!
my next fun is going to be to figure out how to submit to ALL the relational databases at once. This may take a bit.