SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict nimasdj's Avatar
    Join Date
    Dec 2007
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Call php function with jquery

    Before, I was using sajax to call php functions if I need to call it with ajax. Now I prefer to switch to jquery. How is possible to call a php function with jquery?

  2. #2
    SitePoint Zealot bronze trophy xMog's Avatar
    Join Date
    Mar 2011
    Posts
    151
    Mentioned
    3 Post(s)
    Tagged
    2 Thread(s)
    What do you mean with "ajax"? With vanilla JavaScript?

    With JQuery you would do something like this:

    Code:
    $.ajax({
      type: "POST",
      url: "some.php",
      data: { name: "John", location: "Boston" }
    })
      .done(function( msg ) {
        alert( "Data Saved: " + msg );
      });
    JQuery is still JavaScript, only shorter. In fact, JQuery is a JavaScript library.

    You can check out the documentation here: https://api.jquery.com/jQuery.ajax/

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep do what xMog says.

    If you want to call a specific function you could pass a value along to determine which function to call e.g.

    Code:
    $.ajax({
      type: "POST",
      url: "some.php",
      data: { function_to_call: "update_the_db"}
    }));


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
  •