1

I was trying to connect a phonegapp code with my symfony webservice. I am sending data from phonegapp via ajax requests but not finding any way for how to receive that data from symfony2 controller. the code in phone gap is as follows:

function login()
{
 var email = $("#userid").val();
 var pwd = $("#password").val();
 jQuery.ajax({
   type:'POST',
   url: 'http://external.apostle.digibiz.com/web/app_dev.php/api/ajax',
   data: {tag:'ULogin',u_email:email,password:pwd},
   success: function(response)
   {
      var jsObject = JSON.parse(response);
      alert(jsObject);
      if(jsObject==undefined)
      {
    alert('undefined');
      }
      else
      {
    var result = jsObject[0].success;
        if(jsObject[0].success == 1)
        { 
      alert('success');                         
    }
    else
    {
      alert('not varified');
    }               
      }
  }
});

}

the code in my symfony2 controller is written as :

public function ajaxAction(Request $request)
{
    $data = $request->request->get('tag');
    $encoders = array( new JsonEncoder());
    $normalizers = array(new GetSetMethodNormalizer());

    $serializer = new Serializer($normalizers, $encoders);

   // $jsonContent = $serializer->serialize("inserted successfully", 'json');

    $headers = array(
    'Content-Type' => 'application/json'

    );
    $response = new Response($data, 200, $headers);
    return $response; 
}

but on executing on either part no request or response is received. Is there any other way for connection?

Poulami
  • 61
  • 1
  • 1
  • 4
  • Checked the web developer console ( chrome or firefox ) ? If the request starts there must be a log for it. I think the keyword you need to look for is cross browser requests (e.g. http://stackoverflow.com/questions/19003025/phonegap-cross-domain-ajax-post-request-not-working-on-android) I can remember that i implemented an API a while ago for a Phonegap APP with symony and i need to send different headers $response->headers->set('Access-Control-Allow-Origin', '*'); - this would allow any cross domain request – nixoschu Nov 13 '13 at 09:01
  • Ca you give me the exact code for receiving the request from phonegap??? – Poulami Nov 13 '13 at 09:13
  • Sorry I cant was an external implementation, I just did the API. But like i mentioned you need to enable cross domain support for phonegap and whitelist your api server. Dont know excactly if you need to mark the request in another way. – nixoschu Nov 13 '13 at 09:45

0 Answers0