jhecht Posted October 18, 2006 Share Posted October 18, 2006 I dont have a problem about javascript(at the moment), im just writting down some functions i use as bases when i use an AJAX program so that others can use it as well and aren't so lost when all of us on here talk about AJAX coding and so on Javascript file<script type="text/javascript"><!--function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro = new XMLHttpRequest(); } return ro;}var updateId = createRequestObject();function ajax(argument) { updateId.open('GET', "show.php?argument="+argument); updateId.onreadystatechange = handleConts; updateId.send('');}function handleConts() { if(updateId.readyState == 4){ document.getElementById("div_id").innerHTML=updateid.responseText; }}//--></script> show.php<?phpif(isset($_GET['argument'])){//Same name as the thing after the ? in the javascript, right? $arg = (int)$_GET['argument']; $sql = "SELECT * FROM table WHERE user_id=$arg"; $ans= mysql_query($sql) or die(mysql_error()); while($res = mysql_fetch_array($ans)){ echo " Welcome ."$res['user_name']." ! <br/>\n"; } }else{echo "Argument Variable not set.<br/>\n";}?>This echoes out a username from a database given by a user_id passed through the argument variable in show.php. Added by request. By changing the script around a little bit you can suit this to do anything you need pretty much. Link to comment Share on other sites More sharing options...
wallyson Posted October 18, 2006 Share Posted October 18, 2006 I dont have a problem about javascript(at the moment), im just writting down some functions i use as bases when i use an AJAX program so that others can use it as well and aren't so lost when all of us on here talk about AJAX coding and so on<script type="text/javascript"><!--function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro = new XMLHttpRequest(); } return ro;}var updateId = createRequestObject();function ajax(argument) { updateId.open('GET', "show.php?argument="+argument); updateId.onreadystatechange = handleConts; updateId.send('');}function handleConts() { if(updateId.readyState == 4){ document.getElementById("div_id").innerHTML=updateid.responseText; }}//--></script> By changing the script around a little bit you can suit this to do anything you need pretty much. Very nice, now you should add the page show.php with maybe a switch or somethin, to show how its gettin the data and then returning it. Link to comment Share on other sites More sharing options...
jhecht Posted October 20, 2006 Author Share Posted October 20, 2006 Modified original post, please look. Link to comment Share on other sites More sharing options...
Beta Posted October 22, 2006 Share Posted October 22, 2006 Can't you use Ternary Operators to shorten it?like:var request = (window.ActiveXObject)? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();or:request.onreadystatechange = function() {var auth = (request.readyState==4 && request.status==200)? request.responseText : false;? Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 23, 2006 Share Posted October 23, 2006 You can, but really, what's the point? There's no limit to how much code you can put on the page, and it won't increase the loading time by much, if at all, since you're still going through the same process tree. :)And is that you, Outkast? Link to comment Share on other sites More sharing options...
Beta Posted October 23, 2006 Share Posted October 23, 2006 Yes it's me 0uTk4sT. And about the length, alot of people code for forums and things with limited wrapper space, so shortness is better. ( in coding =P ) Link to comment Share on other sites More sharing options...
Chocolate570 Posted October 23, 2006 Share Posted October 23, 2006 Well, as far as I know, the only hosted forum software that gives you a limit on how much code you can stick in is Invisionfree, and almost no one here codes for. Link to comment Share on other sites More sharing options...
Simulationcity Posted January 29, 2007 Share Posted January 29, 2007 You showed the code to use but how do we use it? I'm trying to find someone who has code that works or a tutorial that's easy to understand and so far I haven't found one. Link to comment Share on other sites More sharing options...
jesh Posted January 29, 2007 Share Posted January 29, 2007 You showed the code to use but how do we use it? I'm trying to find someone who has code that works or a tutorial that's easy to understand and so far I haven't found one. Maybe if you had a specific question, or if you had some code that you haven't been able to implement, you could start a new post and someone here can help clear up any confusions you might have. Link to comment Share on other sites More sharing options...
jhecht Posted January 30, 2007 Author Share Posted January 30, 2007 Not to be mean, but if you know javascript at all, in any way, then you should know how to use this; If you don't, then whats the point in you reading and/or replying? If you don't know javascript, then don't complain to us that you can't figure out how to use it. Figure out basic javascript syntax(because this is quite honestly a very BASIC example), and THEN complain that something doesn't work. Link to comment Share on other sites More sharing options...
sree06 Posted February 2, 2007 Share Posted February 2, 2007 This IBM tutorials - mastering AJAX may be helpful :http://www-128.ibm.com/developerworks/view...=Mastering+Ajax Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now