0

I have the following code within a Sharepoint page

$(document).ready(function(){

     $.ajax({
     type:"POST",
     url:"http://somesite.ro/helper.php",
     dataType: 'jsonp', // Notice! JSONP <-- P (lowercase)
     success:function(json){
         // do stuff with json (in this case an array)
         alert("Success");
     },
     error:function(){
         alert("Error");
     }      
    });



});

When I run it it does not alert neither error or success.

EDIT: now it gives me error but if I echo alert("Something"); inside helper.php, it prompts me Something within the Sharepoint page. Why is it giving me error instead of success?

0

I found the answer. The data in the php file was not processed as jsonp because I'm using php 5.1 which doesn't have json_encode function implemented.

So I used jsonwrapper: http://www.boutell.com/scripts/jsonwrapper.html

Full php example code:

require 'jsonwrapper/jsonwrapper.php';

$array = array(
     '0' => array('fullName' => 'Meni Samet', 'fullAdress' => 'New York, NY'),
     '1' => array('fullName' => 'Test 2', 'fullAdress' => 'Paris'),
);

    if(isset ($_GET['callback']))
{


    echo $_GET['callback']."(".json_encode($array).")";

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.