I am really new with Symfony framework I am just trying to implement a simple ajax example:
Routing:
DartDartBundle_data_user:
pattern: /data/user
defaults: { _controller: DartDartBundle:Data:user }
requirements:
_method: POST
DataController:
namespace Dart\DartBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
class DataController extends Controller
{
public function userAction(){
$content = array('success' => true, 'name' => 'luis');
$response = new JsonResponse($content,200);
$response->headers->set('Content-Type', 'application/json; Charset=UTF-8');
return $response;
}
}
And the ajax call:
$.ajax({
type : 'GET',
dataType: 'json',
url : 'http://symfony.dartintelligence.com/app_dev.php/data/user',
success : function(data){
console.log("OK");
console.log(data);
},
error: function (xhr, ajaxOptions, thrownError){
console.log("SOME ERROR OCURRED");
console.log(thrownError);
}
});
But it always fires the error function. I don't know why. I've try without specifying jston dataType and using Response instead of JsonResponse.
I don't know whats wrong.