gpt4 book ai didi

javascript - 将输入保存到 Parse (Javascript)

转载 作者:行者123 更新时间:2023-11-30 00:34:45 25 4
gpt4 key购买 nike

目前,当用户选择一个文件时,它会直接上传到 Parse。我现在添加了一对输入文本字段,例如个人姓名、地址,只有当用户单击选择按钮时,我才会同时将其记录到 Parse 中,一旦用户选择了文件,它就会自动提交.

$(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.
var photo = uploadResult.get("profileImg");
$("#profileImg")[0].src = photo.url();
},
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);
}
});


}

$('#documentFileUpload').bind("change", 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);

parseFile.save().then(
function() {
saveDocumentUpload(parseFile);
},
function(error) {
alert("error");
}
);
});
});
<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>
<form>
<input type="file" id="documentFileUpload">
<br />
<input type="text" value="UserID">
<br />
<input type="text" value="Address">
<br />
<input type="submit" id="documentFileUpload" value="submit">
</form>

更新 2:

    <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>

**Updated 2:**
<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("pWG7YizRnwxRjplGT9RSLoHtFItDtvmc2EK0YJAe", "C2qlan3y2PXi6nwVbACGT6fY3CTus8oVEvNo889u");

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

documentUpload.set("DocumentName", objParseFile);

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

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

// create a pointer by assigning just an ID
var user = new Parse.User();
user.id = user_id;

documentUpload.set('User', user);
documentUpload.set('Address', address);

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>

最佳答案

您有两次“documentFileUpload”:

变化:

<form>
<input type="file" id="documentFileUpload">
<br />
<input type="text" value ="UserID"><br />
<input type="text" value ="Address"> <br />
<input type="submit" id="documentFileUpload" value="submit">

</form>

收件人:

<form>
<input type="file" id="documentFileUpload">
<br />
<input type="text" value ="UserID"><br />
<input type="text" value ="Address"> <br />
<input type="submit" id="documentFileUploadButton" value="submit">

</form>

编辑

要回答您关于记录 UserId 和 Address 字段的评论,请参阅以下代码。我更改了文件上传绑定(bind)到按钮并绑定(bind)了点击事件。这将修复您选择的文件上传问题。

此外,添加了 id 的 user_id 和地址以允许 jQuery 从这些字段中获取值:

$('#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");
}
);
});

然后:

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

关于javascript - 将输入保存到 Parse (Javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27706376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com