View Single Post
Old 06-05-2012, 01:28 PM   PM User | #1
MeltingDog
New to the CF scene

 
Join Date: May 2012
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
MeltingDog is an unknown quantity at this point
JSON with PHP and JQUERY - almost there!

Hi all,

I am pretty much learning JSON from scratch and am having some problems finding good resources. I was wondering if anyone here could just help me push this over the line.

Basically my situation is:

I have a server with a CMS. I want information from the CMS to appear on several other sites.

On a PHP Snippet on the 1st server I have:

Code:
header("content-type: application/json");
header("Access-Control-Allow-Origin", "*")
header("Access-Control-Request-Method", "GET")
header("content-type", "application/x-javascript")

$item1 = 'hello';


$item1 = json_encode($users);
echo $_GET['jasoncallback'] . '(' . $item1 . ')';
On the 2nd .html page I have:

Code:
 $.ajax({ url:"http://localhost/mbff_cms?jsoncallback=?", 
                     dataType: "jsonp", 
                     data: {jsoncallback:'jsoncallback'},
                     success: function(msg) {
                     console.log('server answered:', msg);
                     // do something with received message
                     }
                     });
The result I get in the console is:

GET http://localhost/mbff_cms/?jsoncallb...=1338898608228 jquery-1.7.2.js:8123

Obviously I just want to see the word 'Hello' in the console. I just want to pass the PHP variable over to the .html page and display it using jquery.

Can anyone help me get this over the line?

Thanks heaps!
MeltingDog is offline   Reply With Quote