我正在編寫一個Firefox擴展程序,用於在家中使用。基本上,我需要提交一個PDF文件和一些文本值到一個Web服務。現在我有一個HTML頁面來做到這一點。我需要擴展來自動收集數據並將其提交給Web服務。如何使用Java腳本創建和提交表單
下面是可用的html。
<body>
<form name="frm_upload_file" enctype="multipart/form-data" method="post" action="my web service address">
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td>ClientID</td>
<td><input type="text" name="client_id" /></td>
</tr>
<tr>
<td>HTML</td>
<td><input type="text" name="html" /></td>
</tr>
<tr>
<td align="right" class="inputtxt"> File: </td>
<td class="inputtxt">
<input name="pdf" type="file" />
</td>
</tr>
<tr>
<td align="left" colspan="2" class="inputtxt">
<p><br /><input type="submit" name="submit" value="Submit" /></p>
</td>
</tr>
</table>
這裏有沒有
postToURL: function(html, file) {
var form = content.document.createElement("form");
form.setAttribute("enctype", "multipart/form-data");
form.setAttribute("method", "post");
form.setAttribute("action", "address to my web service");
var clientIDField = document.createElement("input");
clientIDField.setAttribute("type", "text");
clientIDField.setAttribute("name", "client_id");
clientIDField.setAttribute("value", "123456");
form.appendChild(clientIDField);
var htmlField = document.createElement("input");
htmlField.setAttribute("type", "text");
htmlField.setAttribute("name", "html");
htmlField.setAttribute("value", html);
form.appendChild(htmlField);
var fileField = document.createElement("input");
fileField.setAttribute("type", "file");
fileField.setAttribute("name", "pdf");
fileField.setAttribute("value", file);
form.appendChild(fileField);
content.document.body.appendChild(form);
form.submit();
當提交與JS的數據,我從服務器獲取以下異常的JavaScript。 例外
javax.servlet.ServletException:com.sun.jersey.api.container.ContainerException:javax.mail.MessagingException的:缺少啓動邊界
任何想法?
我不認爲你可以創建和填充這樣的文件... – ceejayoz 2009-09-08 19:48:21