2014-12-30 4 views
0

두 개의 텍스트 필드 (사용자 ID 및 주소)와 사용자가 업로드 한 파일을 저장하려고하지만 지원에도 불구하고 시도가 실패했습니다. 코드에 오타가 있는지 확실하지 않지만 Parse에 기록하지 않는 것 같습니다.구문 분석 (자바 스크립트)에 항목 저장

<HTML> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.15.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 

    // *************************************************** 
    // NOTE: Replace the following your own keys 
    // *************************************************** 

    Parse.initialize("id", "id"); 

    function saveDocumentUpload(objParseFile) 
    { 
    var documentUpload = new Parse.Object("Scan"); 
    documentUpload.set("Name", ""); 

    documentUpload.set("DocumentName", objParseFile); 
    documentUpload.save(null, 
    { 
     success: function(uploadResult) { 
      // Execute any logic that should take place after the object is saved. 

     }, 
     error: function(uploadResult, error) { 
      // Execute any logic that should take place if the save fails. 
      // error is a Parse.Error with an error code and description. 
      alert('Failed to create new object, with error code: ' + error.description); 
     } 
    }); 
    } 

    $('#documentFileUploadButton').bind("click", function (e) { 
     var fileUploadControl = $("#documentFileUpload")[0]; 
     var file = fileUploadControl.files[0]; 
     var name = file.name; //This does *NOT* need to be a unique name 
     var parseFile = new Parse.File(name, file); 

     var user_id = $('#user_id').val(); 

     var address = $('#address').val(); 


     parseFile.set('UserId', user_id); 
     parseFile.set('Address', address); 


     parseFile.save().then(
       function() { 
        saveDocumentUpload(parseFile); 
       }, 
       function (error) { 
        alert("error"); 
       } 
     ); 
    }); 
}); 
</script> 

<body><form> 
    <input type="file" id="documentFileUpload"> 
    <br/> 
    <input type="text" placeholder="UserID" id="user_id"> 
    <br/> 
    <input type="text" placeholder="Address" id="address"> 
    <br/> 
    <input type="submit" id="documentFileUploadButton" value="submit"> 
</form> 
</body> 
</HTML> 

는 업데이트 : 당신의 API 키가 제대로 입력

<HTML> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.15.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function() { 

    // *************************************************** 
    // NOTE: Replace the following your own keys 
    // *************************************************** 

    Parse.initialize("ID", "ID"); 

    function saveDocumentUpload(objParseFile) 
    { 
    var documentUpload = new Parse.Object("Scan"); 
    documentUpload.set("Name", ""); 

    documentUpload.set("DocumentName", objParseFile); 
    documentUpload.save(null, 
    { 
     success: function(uploadResult) { 
      // Execute any logic that should take place after the object is saved. 

     }, 
     error: function(uploadResult, error) { 
      // Execute any logic that should take place if the save fails. 
      // error is a Parse.Error with an error code and description. 
      alert('Failed to create new object, with error code: ' + error.description); 
     } 
    }); 
    } 

    $('#myForm').bind("submit", function (e) { 
    e.preventDefault(); 
     var fileUploadControl = $("#documentFileUpload")[0]; 
     var file = fileUploadControl.files[0]; 
     var name = file.name; //This does *NOT* need to be a unique name 
     var parseFile = new Parse.File(name, file); 

     var user_id = $('#user_id').val(); 

     var address = $('#address').val(); 


     parseFile.set('UserId', user_id); 
     parseFile.set('Address', address); 


     parseFile.save().then(
       function() { 
        saveDocumentUpload(parseFile); 
       }, 
       function (error) { 
        alert("error"); 
       } 
     ); 
    }); 
}); 
</script> 

<body><form id='myForm'> 
    <input type="file" id="documentFileUpload"> 
    <br/> 
    <input type="text" placeholder="UserID" id="user_id"> 
    <br/> 
    <input type="text" placeholder="Address" id="address"> 
    <br/> 
    <input type="submit" value="submit"> 
</form> 
</body> 
</HTML> 
+0

내 질문은 그게 왜 해결하세요. –

+0

공유되는 코드는 동일합니다. (그래서 당신은 그것이 중복이라고 말하는 것입니까?) – Hacketo

+0

제출을 가로 채는 대신에 보통 양식을 게시하는 것처럼 보입니다. 양식을 제출할 때 페이지가 다시로드됩니까? – Jack

답변

0

먼저해야합니까? 나는 당신이이 글을 여기에 올리도록 변경했다고 가정하고 있지만 그렇지 않다면 그들은 당신의 열쇠가 필요합니다.

Parse.initialize("id", "id"); 

정상적으로 양식이 다시 게시되므로 자바 스크립트가 실행되지 않습니다.

버튼을 아래로 클릭하여 변경하십시오.이 양식에 ID를 부여하십시오.이 예에는 ID가 myForm입니다. 대신

:

$('#documentFileUploadButton').bind("click", function (e) { 
    //your code to run 
}); 

시도 : 나는 수 없습니다

$('#myForm').bind("submit", function (e) { 
    e.preventDefault(); 
    //your code to run 
}); 
+0

고마워, 제출 입력을위한 ID를 제거합니까 –

+0

@SystemAdminstrator 무슨 뜻인지 잘 모르겠습니다. 제출 버튼에는 ID가있을 수 있으며 더 이상 사용하지 않습니다. 제출 양식을 바인드 할 양식에 양식을 제공하려고합니다. – Jack

+0

clarifcation 주셔서 감사합니다. 나는 폼에 ID를 제공했지만 제출시 "Uncaught TypeError : undefined is functionfile.html : 46 (익명 함수) jquery.min.js : 3 o.event.dispatchjquery.min"키를 누르면 콘솔에 다음 오류가 표시됩니다. js : 3 r.handle "귀하의 예의에 대해이 메시지에 업데이트 된 코드를 첨부했습니다. –