2014-09-01 3 views
1
<script type="text/javascript"> 
        $('#fileUpload').submit(function (evt) { 
         evt.preventDefault(); 
         $.ajax({ 
          url: "/Transport/GridUpload", 
          type: 'POST', 
          data: $("#fileUpload").serialize(), 
          success: function (response) { 
          alert("it Works"); 
          } 
         }); 
        }); 
       </script> 

양식을 Ajax를 통해 게시하려하지만 작동하지 않습니다.Jquery 양식 제출이 작동하지 않습니다.

양식 HTML :

@using (Html.BeginForm("GridUpload", "Transport", new { tipas = 1 }, FormMethod.Post, new {enctype="multipart/form-data", id = "fileUpload" })) 
        { 
         <table style="margin-top:0px;"> 
          <tr> 
           <td> 
            <label for="file">Filename:</label> 
           </td> 
           <td> 
            <input type="file" name="file" id="file" /> 
           </td> 
           <td> 
            <input type="submit" class="upload-button" value="Upload" /> 
           </td> 
          </tr> 
         </table> 
        } 

내가 얻을 오류 :

POST http://localhost:3043/Transport/GridUpload 500 (Internal Server Error) 

내 코드에 어떤 문제가 될 수있다? 내가 놓친 게 있니? 레코드의 경우 evt.preventDefault()를 제거하면; 모든 것은 작동하지만 아약스없이 폼을 제출하는 것을 막을 필요가 있습니다.

+0

<input type="button" id="fileUpload" class="upload-button" value="Upload" /> $('#fileUpload').click(function (evt) { 

변화는 모두 함께 –

+0

"모든 작품,하지만 난 아약스없이 양식을 방지 할 필요가있다." - 아약스 제출 만하면 돼? 그래서 $ ('# fileUpload')를 변경해야합니다. 무엇을 제출 하시겠습니까? –

+0

ur 코드에서 양식을 통해 일부 데이터를 업로드하는 것을 보았습니다. 여기에 제출해야합니다. Ajax는 작동하지 않습니다. –

답변

0

변경은 SUMIT와 Ajax를 수행하지 못할

@using (Html.BeginForm("GridUpload", "Transport", new { tipas = 1 }, 

FormMethod.Post, new {enctype="multipart/form-data", id = "fileUpload1" })) 
+0

업로드 방법 코드가 작동합니까? 그것의 올려주기 자료로 –

+0

@ 아주 좋은 점 – Amit

+0

왜 Downvote !!! – Amit

관련 문제