我想将 JSON 对象发布到 asp.net 页面。我浏览了整个网络,并了解了如何调用 Web 服务或使用 AJAX 发送或检索 JSON 的页面方法,但我想发布 JSON。
原因是我想动态创建一个 PDF 文档,这个 PDF 文档将包含表格内的信息。
这是我尝试过的:
function GetTableValuesAndPost()
{
try {
GetAllTableRows("N");// the N stands for not actually submitting to the database same method is used to submit
// for processing and create pdf method.
var tableValues = '{' + 'w_vendor:[' + w_vendor + "],w_invoice:[" + w_invoice + "],w_invdate:[" + w_invdate + "]," + "w_amount:[" + w_amount + "]," +
"w_account:[" + w_account + "]," + "w_fund:[" + w_fund + "]," + "w_org:[" + w_org + "]," + "w_prog:[" + w_prog + "]," + "w_adrsstyp:[" + w_adrsstyp + "]," +
"w_adrss_seq:[" + w_adrss_seq + "]," + "w_Row:[" + w_Row + "]," + "w_bank:[" + w_bank + "]," + "w_user:[" + w_user + "]," + "w_addl_info:[" + w_addl_info + "]," + "w_type:[" + w_type + "]" + "}"
//var tableValues2 = ('w_vendor:' + w_vendor);
//JSON.stringify({ FWTMP_FIXINV_INV_NUM: FWTMP_FIXINV_INV_NUM })
//var tableValues = document.getElementById(ParseTable).innerHTML;
var CreateForm = document.createElement('form');
CreateForm.setAttribute('method', 'post');
CreateForm.setAttribute('target', '_blank');
CreateForm.setAttribute('name', 'pdfgetter');
CreateForm.setAttribute('id', 'pdfgetter');
CreateForm.action = "./PDFcreator.aspx";
var Fld2 = document.createElement('input');
Fld2.setAttribute('type', 'hidden');
Fld2.setAttribute('name', 'pdfvalue');
Fld2.setAttribute('value', tableValues);
CreateForm.appendChild(Fld2);
document.body.appendChild(CreateForm);
CreateForm.submit();
}
catch (err) {
alert(err);
}
}
这将创建表单并将数据发布到预期页面。但是,我遇到的问题是,在接收端,我最终得到了一堆乱七八糟的字符,比如%3245910241630%
.
我认为这是一个编码问题,那么我应该如何使用 JavaScript 或 jQuery 对其进行编码?
任何想法都会有所帮助,如果它们是实现这一目标的更好方法,那也会有所帮助。