我想知道是否可以使用getJSON上传文件?基本上我有一个表格,人们可以选择word docs或pdf,但我的表单是使用getJSON(下面的代码)处理的,我不知道如何将文件上传与getJSON合并?
<form name="employment" id="employment" enctype="multipart/form-data">
<div id="contactform">
<div class="information">
<label>Full Name: *</label>
<input type="text" name="name" id="name" class="inputbox required" />
</div>
<div class="information">
<label>Email Address: *</label>
<input type="text" name="email" id="email" class="inputbox required email" />
</div>
<div class="information">
<label>Contact Number: *</label>
<input type="text" name="number" id="number" class="inputbox required" />
</div>
<div class="information">
<label>Position: *</label>
<select name="position" id="position" class="inputbox required">
<option value="">- Please Select-</option>
<?php foreach($this->Positions as $position) { ?>
<option value="<?php echo $position->name; ?>"><?php echo $position->name; ?></option>
<?php }; ?>
<option value="Traineeship">Traineeship</option>
<option value="Clerkship">Clerkship</option>
</select>
</div>
<div class="information">
<label>Cover Letter:</label>
<textarea name="letter" id="letter" class="inputbox"></textarea>
</div>
<div class="information">
<label>Please upload your resumé in PDF or Word format (less than 2MB)*:</label>
<input type="file" name="resume" id="resume" class="inputbox" />
</div>
<input type="submit" name="submit" id="submit" value="Submit" class="submitButton" />
</div>
<div class="clear"></div>
</div>
</form>
这是我的jquery,但我不确定它是否会以这种方式传递文件?
$("#employment").validate({
submitHandler: function(form) {
var name = $("#name").val();
var email = $("#email").val();
var number = $("#number").val();
var position = $("#position").val();
var letter = $("#letter").val();
var resume = $("#resume").val();
$.getJSON("/index.php?option=com_json&format=raw", { task: "employment", e_name: name, e_email: email, e_number: number, e_position: position, e_letter: letter, e_resume: resume }, function(data) {
var response = eval(data);
if (response["result"] == 1) {
$("form#employment").hide();
$("#loading").empty();
$("#loading").append("<strong>Thank you for submitting your resume.</strong>");
} else if (response["result"] == 3) {
alert("There has been an error, please try again.");
$("#loading").empty();
$("form#employment").show();
} else {
alert("There has been an error, please try again.");
$("#loading").empty();
$("form#employment").show();
};
});
}
});
答案 0 :(得分:2)
您无法使用getJSON上传文件。要上传文件,method
表格应为post
,您需要提交表单。试试文件上传插件。