当前位置: 动力学知识库 > 问答 > 编程问答 >

jquery - Symfony 2, ajax

问题描述:

I have big problem because i can't make AJAX request in Symfony.

I have some code in template

 $( document ).ready(function() {

$( ".data" ).change(change_selected);

});

function change_selected(){

$.ajax({

type: "POST",

url: "{{path('validate')}}",

data: {'name' : 'kk'},

cache: "false",

dataType: "html",

success: function(response) {

alert('asd');

}

});

}

and i made controller with function

/**

* @Route("/validate_form", name="validate")

* @Template()

*/

public function ajaxeAction()

{

if($request->isXmlHttpRequest()) {

$response = new Response();

$output = array('success' => true);

$response->headers->set('Content-Type', 'application/json');

$response->setContent(json_encode($output));

return $response;

}

}

when i run firebug and change a text in the input field then firebug return error "500 Internal Server Error - ...test/web/app_dev.php/validate_form""

Someone know why ?

网友答案:

you didn't init function with Request $request?

public function ajaxeAction(Request $request){..}
分享给朋友:
您可能感兴趣的文章:
随机阅读: