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

zoom an image on a coordinate using jquery on onclick

javascript jquery ajax

I want to zoom an JPEG image with predefined image coordinates using onclick function.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.