Symfony Ajax Controller Handler, always fires jQuery error function

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.

Answers


First

Route is configured as POST - only

The Ajax request is a GET request

try to remove the requirement

Second

Try to access the url directly in your browser to check if you configured the path right and you can access the controller.


The request is made from the same server but with a different domain. The request is not using any vhost or domain, its uses server's ip and the htdocs folder.

Symfony is placed in a folder which has a vhost alias and its accessed using a domain (i.e. symfony.dartintelligence.com/app_dev.php/data/user). The folder in the server is inside /DART root folder. So its ./DART/symfony....

The firebug info for either of the methods. For instance, for GET method: https://www.dropbox.com/s/r9o6kbsnlyhibxo/screen_capture_20131120_GET_method.png


Need Your Help

Java ME UI libraries

java java-me mobile

I'm developing a Java ME app & need pointers to some really good UI libraries. I did see a few such as Java ME Polish. Are there any more out there? For e.g. ebuddy's java ME app has an amazing...

NOT IN clause and NULL values

sql sql-server tsql null notin

This issue came up when I got different records counts for what I thought were identical queries one using a not in where constraint and the other a left join. The table in the not in constraint ha...