?
Solved

PHP Post Request JSON

Posted on 2011-02-18
12
Medium Priority
?
456 Views
Last Modified: 2012-05-11
Hi all,

I need some example code to be able to get some info from an api.

This is what I've got from the api:

Method is:

http://www.mydomain.com/api/set/

and

http://www.mydomain.com/api/get/

Parameters/ Example Request

{
    'site': 'mysite',
    'id': 'some_id',
    'stage': 2,
}

and for the get

{
    'site': 'mysite',
    'id': 'some_id',
}

example resplonses would be:

for set:

{"status": "successful", "data": {}}

and for get:

{"status": "successful", "data": {stages: [1,1,0,1]}}


I just need some client code to get and set the information from the api ...

Hope all this info helps as it's all I have.

Thanks

0
Comment
Question by:error77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
12 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34924590
check jquery ajax
http://viralpatel.net/blogs/2009/04/jquery-ajax-tutorial-example-ajax-jquery-development.html
http://api.jquery.com/jQuery.ajax/

for example, for get

$.get(
    "http://www.mydomain.com/api/get/",
    "{
        'site': 'mysite',
        'id': 'some_id',
    }",
    function(data) { alert(eval(data).status); }
);


Similarly for set
0
 

Author Comment

by:error77
ID: 34924645
OK, I've done the above and to call the function added this:

<input type="button" value="Click Here" onClick="data();">

but nothing happens ... anything I'm doing wrong?

Thanks

0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 34924684
what is data() ??

and what exactly do you want to do with the data?
0
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 

Author Comment

by:error77
ID: 34924700
I want to go to that url and have some data returned ... for new an alert message with the return will do.

0
 

Author Comment

by:error77
ID: 34924721
In other word...post a request and get some data returned so I can then use them.
0
 

Author Comment

by:error77
ID: 34924728
As for your question;  What is data ...

I got it from your code:

$.get(
    "http://www.mydomain.com/api/get/",
    "{
        'site': 'mysite',
        'id': 'some_id',
    }",
    function(data) { alert(eval(data).status); }
);

function(data)  <-- so I guess the function was called data?
0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 total points
ID: 34924793
no this function is not data.
In fact this is an anonymous callback handler

You need to put your get handler in data method to call it that way

function data()
{
 $.get(
    "http://www.mydomain.com/api/get/",
    "{
        'site': 'mysite',
        'id': 'some_id',
    }",
    function(data) { alert(eval(data).status); }
);
   
}
0
 

Author Comment

by:error77
ID: 34924832
OK, tried that but nothing is popup up .. how do I get a popup out this with the return please?

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34925295
What is the actual URL of the web service?  Please post some test data so we can test the code to access the service.  Thanks.
0
 

Author Comment

by:error77
ID: 34926122
Sorry, I can't do that :o/
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34926161
Well, if you can't post the actual URL, at least take the time to set up a test case that works the same way.  You're asking us for assistance - it would seem reasonable that you would give the fellow experts something more tangible than "please help me get my data right and btw, I will not let you see you my data."
0
 

Author Closing Comment

by:error77
ID: 34926166
My mistype. It's now working fine thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question