SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Aug 2012
    Location
    Bandung, Indonesia, Indonesia
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need sample PHP web service for $.ajax

    Hi,

    I need a simple example of PHP webservice that will be consumed using jQuery.ajax.
    If you have any references regarding it please share to me.

    Thanks in advance.
    Samuel

  2. #2
    Under Construction silver trophybronze trophy AussieJohn's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    776
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Hey Samuel,

    I wrote something super basic for this once, here is a basic extract:

    PHP Code:
    $json "";

    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : "";
        
    if (
    $action == "do_something") {                
        
    $data do_some_action_that_returns_an_object();               
        
        
    //json encode your data        
        
    $json json_encode($data);    
    }

    header("Content-type: application/json");    

    print 
    $json
    You just specify some parameters and then "do something" based on those parameters. You can then json_encode() your results and print them to have your data returned as a JSON result.

    Please note that this is super super basic, and I haven't used this for anything other than some personal things, but if you simply want to test ajax functionality then it will do the trick.


    P.S. if you're interested in testing AJAX functionality with jQuery, you might find that "Mockjax" will suffice: https://github.com/appendto/jquery-mockjax
    Last edited by AussieJohn; Aug 21, 2012 at 19:30. Reason: code formatting
    var details = {
    . . web: "afterlight.com.au",
    . . photos: "jvdl.id.au",
    . . psa: "usethelatestversion.com"
    }

  3. #3
    SitePoint Member
    Join Date
    Aug 2012
    Location
    Bandung, Indonesia, Indonesia
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you.

    It's enough for me.


Tags for this Thread

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
  •