phpQuestioner Posted July 5, 2007 Share Posted July 5, 2007 Ok, so I really do not know much about AJAX (at all), but I want to learn how to do something. I have been reading a few articles, but still do not quiet understand how to do this. I have a PHP routine that I created in a my PHP page and I want to use AJAX to query my routine. So I create a function; something like this: function page2() { if (page == 2) { echo "You Are On Page 2"; } else { echo "You Are On Page 1"; } } And my link is like this: http://www.domain.com/index.php?page=2 So can some one explain how I can use AJAX to query my page or will AJAX only work with database? Also when I use a AJAX routine; how would I like the page; like this: javascript:ajaxrountie1() or like still this: http://www.domain.com/index.php?page=2 Can anyone tell me how to go about doing this? Quote Link to comment https://forums.phpfreaks.com/topic/58491-newbie-ajax-php-query-question/ Share on other sites More sharing options...
bibby Posted July 7, 2007 Share Posted July 7, 2007 I think you have your roles mixed up. javascript != ajax , essentially. I think that you may have gone down the road of AJAX because you want to turn the page without reloading? If you are, here are duty assignments: The database has the page content, PHP identifies the page and returns the page content Javascript will handle keeping track of the current page. There's nothing ajax'y about your page2 function at all. the AJAX role in this business is to ask for and display new content. If you are following this link , index.php?page=2 The business of getting the page 2 content to the page is between php & mysql. Javascript can decide through functions whether or not to call ajax. Ajax could then ask php&mysql for page1 content if you told it to. Quote Link to comment https://forums.phpfreaks.com/topic/58491-newbie-ajax-php-query-question/#findComment-292044 Share on other sites More sharing options...
phpQuestioner Posted July 7, 2007 Author Share Posted July 7, 2007 OK - so can you give me a basic AJAX example and how I would use a link to query AJAX to pull content from my database without reloading my PHP web page. How do I use a basic non javascript link (ie http://www.domain.com/page1.php?id=4379) to fire off an AJAX routine that will query my database and automatically update the content of the page I am currently on, without reloading my page? Quote Link to comment https://forums.phpfreaks.com/topic/58491-newbie-ajax-php-query-question/#findComment-292095 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.