Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/58491-newbie-ajax-php-query-question/
Share on other sites

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.

 

 

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.