gpt4 book ai didi

javascript - 在 JS/C#/MVC4 中将 json 转换为 csv 文件并填充 AccessDB

转载 作者:行者123 更新时间:2023-12-03 11:18:30 25 4
gpt4 key购买 nike

我的网站出现问题。我目前有一份申请表并提交了该表格,并发送了一封电子邮件。我希望我可以创建一个 csv 文件来发送表单。其次,通过此 CSV 文件自动填充我的数据库访问权限。

我的 ASP 表单:

<div class="submit">
<div class="left">
<div class="field"><input id="inputFirstname" type="text" value="First name *" class="watermark" name="firstname"/></div>
<div class="field"><input id="inputLastname" type="text" value="Last name *" class="watermark" name="lastname"/></div>
<div class="field"><input id="inputEmail" type="text" value="E-mail *" class="watermark" name="email"/></div>
<div class="fieldradio" style="margin-bottom:10px;">
<label class="watermark" style="display:inline">Gender *</label>
<input id="inputGenderM" class="watermark" style="display:inline;width: 10px" name="gender" type="radio" />
<label class="watermark" style="display:inline">M</label>
<input id="inputGenderF" class="watermark" style="display:inline;width: 10px" name="gender" type="radio" />
<label class="watermark" style="display:inline">F</label>
</div>
</div>
<div class="right">
<div class="textarea"><textarea id="inputMessage" name="message" class="watermark">Add your message here</textarea></div>
<div style="float:left;width:100%; margin-top:30px;">
<div id="captchadiv"><input id="captchaInput" type="text" value="Enter validation text *" name="captchaInput" class="watermark" style="margin-top:10px;"/></div>
</div>
<div class="clear"></div>
<div class="submit_container" id="submitArea">
<a onclick="javascript:submitCV();" class="btn orange height_19 submit"><span>
SEND FORM</span></a>
</div>
</div>

我的函数 JS“submitCV()”:

$(document).ready(
function(){

$.getJSON('http://jsonip.appspot.com/?callback=?',
function(data){
clientIP = data.ip;
});

function submitCV() {
if( $("#inputFirstname").val() == false)
{
$('#inputFirstname').addClass('errorValidationSubmit');
alert('Please fill the FirstName field ');
return;
}
if($("#inputLastname").val() == false)
{
$('#inputLastname').addClass('errorValidationSubmit');
alert('Please fill the LastName field ');
return;
}

var genderId = $('input[name=gender]:checked').attr('id');
if(typeof genderId == 'undefined')
{
$('.fieldradio').addClass('errorValidationSubmit');

alert('Please choose a gender ');
return;
}

if( validateEmail($("#inputEmail").val()) == false)
{
$('#inputEmail').addClass('errorValidationSubmit');
alert('Invalid e-mail address.');
return;
}
if( $(".submit .dropdown dt a").attr('href') =="#"){
$('.submit .dropdown').addClass('errorValidationSubmit');
alert('Please select an open position');
return;
}

if($("#captchaInput").val() == false || $("#captchaInput").val().length != 5)
{
$('#captchaInput').addClass('errorValidationSubmit');
$('.realperson-text').addClass('errorValidationSubmit');
alert('Please fill the Validation Text Field with the Captcha (5 characters)');
return;
}


var path = $(location).attr('href');

var capchallenge = cleanJSONString($(".realperson-hash").val());
//Recaptcha.get_challenge();
var capresponse = cleanJSONString($("#captchaInput").val());
//Recaptcha.get_response();
try {
var parameters = '{ "url" : "' + escape(path) +
'", "clientip" : "' + clientIP +
'", "firstname" : "' + cleanJSONString($("#inputFirstname").val()) +
'", "lastname" : "' + cleanJSONString($("#inputLastname").val()) +
'", "gender" : "' + cleanJSONString(genderId) +
'", "email" : "' + cleanJSONString($("#inputEmail").val()) +
'", "message" : "' + cleanJSONString($("#inputMessage").val()) +
'", "position" : "' + cleanJSONString($(".submit_cv .dropdown dt a").attr('href')) +
'", "captchachallenge" : "' + capchallenge +
'", "captcharesponse" : "' + capresponse + '" }';

contentSubmit = $("#submitArea").html();
$("#submitArea").empty().html('<img src="/Style%20Library/ajax-loader.gif" />');

jQuery.ajax({
type: "POST",
url: '_vti_bin/json/monservice.svc/submit',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: parameters,
success: function (msg) {
submitSucceeded(msg);
$("#submitArea").empty().html(contentSubmit);
resetRealPersonCaptcha();
alert(parameters);
},
error: submitFailed
});
}
catch (e) {
alert('Error invoking service' + e);
clearUploadPart();
}
//Recaptcha.reload();
}
function submitSucceeded(result) {
alert(result.submitResult);

if (!result.submitResult.contains("The captcha verification didn't work. Please try again")) {
clearUploadPart();
}
}
function submitFailed(error) {
alert('An error occured.');
//clearUploadPart();
resetRealPersonCaptcha();
$("#submitArea").empty().html(contentSubmit);
}

是否有相对快速的机会来创建要存储在一个地方的 CSV 文件?你有什么推荐?

另一方面,我希望每个新的 CSV 文件都可以填充 Access 数据库。如果我的 CSV 文件位于 FTP 文件夹中,您可能是 Unix 脚本还是简单的 VB?

最佳答案

如果您能够从表单中获取 JSON 数据,请使用以下方法 JSONTOCSVConverter :

function JSONToCSVConvertor(JSONData, ReportName, ShowLabel) {

//If JSONData is not an object then JSON.parse will parse the JSON string in an Object
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;

var CSV = '';
if (ShowLabel) {
var row = "";
//This loop will extract the label from 1st index of on array
for (var index in arrData[0]) {
//Now convert each value to string and comma-seprated
row += index + ',';
}
row = row.slice(0, -1);

//append Label row with line break
CSV += row + '\r\n';
}
//1st loop is to extract each row
for (var i = 0; i < arrData.length; i++) {
var row = "";
//2nd loop will extract each column and convert it in string comma-seprated
for (var index in arrData[i]) {
row += '"' + arrData[i][index] + '",';
}
row.slice(0, row.length - 1);
//add a line break after each row
CSV += row + '\r\n';
}
if (CSV == '') {
alert('No data available');
return;
}
//this will remove the blank-spaces from the title and replace it with an underscore
var fileName = ReportName.replace(/ /g, "_");

//Initialize file format you want csv or xls
var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);

//this trick will generate a temp <a /> tag
var link = document.createElement("a");
link.href = uri;

//set the visibility hidden so it will not effect on your web-layout
link.style = "visibility:hidden";
link.download = fileName + ".csv";

//this part will append the anchor tag and remove it after automatic click
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}

关于javascript - 在 JS/C#/MVC4 中将 json 转换为 csv 文件并填充 AccessDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27225575/

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