SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ajax and php [help]

    Hi,

    I have a very complicated question that involves some php. I have a database I am pulling information from using ajax which specks to a php page which pulls the info. Now this info pulled is a link which its id behind it eg)
    Code:
     <a href="something.php?id=1>"
    now when i click on this link I get additional information the item. My issue comes in as into how I should call this information using ajax I know how to do it with php but how do i pull the correct values from the db using ajax?

    I hope this question is clear.

  2. #2
    SitePoint Addict dnordstrom's Avatar
    Join Date
    Jul 2006
    Location
    Amsterdam
    Posts
    337
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Hard to really answer that without more information about how you have implemented the site.

    An AJAX call is a request just like the one your web browser sends your web server when you visit the site—it's just that the Javascript makes the request asynchronously. So the Javascript code receives the results it requests from the server, instead of you seeing the results directly in the browser. In general, when you visit the site you most likely want to show the whole layout, but using AJAX you only want to return the relevant data and for example not a header, footer etc.

    What I'm saying is, your Javascript will make an AJAX call to a PHP script that will fetch the data you want so while using Javascript on the client-side you'll still be using PHP on the server-side. (Javascript can of course be used server-side too if you want but you most likely don't want that.) You can make an AJAX call to "something.php?id=1&ajax=true", and have the PHP script check the value of "ajax". If true, it will return only the relevant data and you can choose what you want to do with it—for example, you can display it in a certain element on the currently loaded page.

    Basically, an AJAX call is not much different from any other request. It calls (in this case) a PHP script that fetches the information from the database, and then it likely does something fun with the result it gets.

    Anyway, as mentioned earlier, it's somewhat difficult to explain unless I have more details about the implementation, how the site is built, how it's loaded on the server side etc. NetTuts+ has a few examples here on how to do AJAX calls with the jQuery framework and you can find a whole bunch of information by searching for PHP and AJAX.

    Good luck with this.
    Daniel Nordstrom. of. Nintera(ctive)
    -- Featured post: Part 2. Writing NI.JS JavaScript
    ----- Follow me on Twitter. Got project? Contact me.
    -------- SitePoint: Community Guidelines Be A Great Member

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I will post the code I am using later hopefully someone could solve my issue

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2011
    Location
    Trinidad and Tobago
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So here is the code my html page is what uses javascript to call the php file. However my php file returns a link with the id embedded in it such as mentioned before <a href="something.php?id=1"> when the user clicks this link it sends him to a php page with all the details on the link he clicked. I want to change this from being done by php only. I want to implement this will ajax. How is this possible. Files are attached to this post. Note that new_article.html calls new_articles.php the results are links when clicked the file article_desc.php is called (this is the call i want to use ajax for).
    Attached Files Attached Files


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •