2013-02-07 3 views
0

jquery를 사용하여 간단한 파일 업 로더를 만들려고합니다. Symfony2없이 내 서버에서 테스트 해 보았습니다.Symfony 2 jquery form

나는 두 가지 간단한 컨트롤러를 사용

{% extends '::base.html.twig' %} 
{% block script %} 
<script type="text/javascript"> 
    <!-- 
    $(document).ready(function() { 


     var options = { 
     target: '#message', //Div tag where content info will be loaded in 
     url: {{ path('newproject') }}, //The php file that handles the file that is uploaded 
     beforeSubmit: function() { 
      $('#uploader').html('<img src="ajax-loader.gif" border="0" />'); //Including a preloader, it loads into the div tag with id uploader 
     }, 
     success: function() { 
      //Here code can be included that needs to be performed if Ajax request was successful 
      $('#uploader').html('Plik przesłany'); 

     } 
     }; 

     $('#upload').submit(function() { 
      $(this).ajaxSubmit(options); 
      return false; 
     }); 

    }); 
//--> 
</script> 
{% endblock %} 



{% block body %} 
<div id="message"></div> 
<form name="upload" id="upload" action="#" method="POST" enctype="multipart/form-data"> 
    <table cellpadding="4" cellspacing="4" border="0"> 
     <tr> 
      <td colspan="2"><h1>Upload File via Ajax</h1></td> 
     </tr> 
     <tr> 
      <td nowrap>File:</td> 
      <td nowrap><input type="file" name="fileToUpload" id="fileToUpload" /></td> 
     </tr> 
     <tr> 
      <td nowrap colspan="2"><input type="submit" id="uploadFile" value="Upload File" /></td> 
     </tr> 

    </table> 
</form> 
<div id="uploader"></div> 
{% endblock %} 

당신이 내가 왜 작동하지 않는 말할 수

/** 
* @Route("/") 
* @Template() 
*/ 
public function indexAction() 
{ 
    return array(); 
} 

/** 
* @Route("/new_project", name="newproject") 
* @Method("POST") 
*/ 
public function newProjectAction() 
{ 
    $entity = new test(); 
    $entity->setName('test'); 

    $em = $this->getDoctrine()->getManager(); 
    $em->persist($entity); 
    $em->flush(); 


    return new Response('<html><body>added</body></html>'); 
} 

그리고 내 인덱스보기를?

<script type="text/javascript"> 
    //<!-- 
    $(document).ready(function() { 

오류를 보여 u는 jQuery 라이브러리가 페이지에 포함되어 있는지 확인도 사용 r에있는 브라우저 언급 시도하십시오에

+0

실행할 때 JavaScript 오류가 있습니까? 렌더링 된 HTML은 어떻게 생겼습니까? – cheesemacfly

답변

0
<script type="text/javascript"> 
    <!-- 
    $(document).ready(function() { 

변화를.