[英]How to assign variable value to a xml field within ajax block
I am new to ajax. 我是ajax的新手。 ,I have problem with adding XML data field in ajax query. ,我在ajax查询中添加XML数据字段时遇到问题。
$.ajax({
type: "POST",
url: "communication.cgi",
async: true,
cache: false,
data: "<Message MainPageID=\"0\" pageID=\"1\" WebpageName=\"page1\" Action=\"upload\" />",
datatype: "text",
error: function(jqXHR, textStatus, errorThrown)
{
//TODO
},
success: function(data)
{
//TODO
}
});
From the above data field, i need add filename as another one new field. 从上面的数据字段,我需要添加文件名作为另一个新字段。 The filename is stored in a variable like, 文件名存储在变量中,
var filename = $("#file_selector_upload").val(); var filename = $(“#file_selector_upload”)。val(); // filename depends on uploaded file name. //文件名取决于上传的文件名。
Now, This filename field need to add with the above said data field. 现在,此文件名字段需要添加上述数据字段。 how can add it? 怎么能加呢?
I would send the data as an JSON Object instead of XML like this: 我会将数据作为JSON对象而不是XML发送,如下所示:
$.ajax({
type: "POST",
url: "communication.cgi",
async: true,
cache: false,
data:
{
'Message':
{
'MainPageID': 0,
'pageID': 1,
'WebpageName': 'page1',
'Action': 'upload',
'filename': $("#file_selector_upload").val()
}
},
datatype: "JSON",
error: function(jqXHR, textStatus, errorThrown)
{
//TODO
},
success: function(data)
{
//TODO
}
});
But if you want to send it as XML, why dont just manipulate the XML-String? 但是如果你想把它作为XML发送,为什么不只是操纵XML-String?
$.ajax({
type: "POST",
url: "communication.cgi",
async: true,
cache: false,
data: '<Message filename="'+$("#file_selector_upload").val()+'" MainPageID="0" pageID="1" WebpageName="page1" Action="upload" />',
datatype: "text",
error: function(jqXHR, textStatus, errorThrown)
{
//TODO
},
success: function(data)
{
//TODO
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.