我有这个 ajax/jquery 代码:
var headline = $("input#headline").val();
var subheadline = $("textarea#subheadline").val();
var pics = $("input#pics").val();
var dataString = 'headline='+ headline + '&subheadline=' + subheadline + '&pics=' + pics;
$(".save-notice").hide();
$.ajax({
type: "POST",
url: "web-block/forms/process-001.php",
data: dataString,
success: function() {
$(".save-notice").show();
$(this).parents(".manage-content-wrap").next(".ribbon-content").fadeIn();
}
});
另一方面,我有这个 HTML 表单:
<form action="" id="select-block" class="general-form">
<div class="input-wrap">
<input class="clearme" name="Headline" value="<?php echo $Headline;?>" id="headline"/>
</div>
<div class="input-wrap">
<textarea class="clearme" name="Sub-Headline" id="subheadline"><?php echo $SubHeadline;?></textarea>
</div>
<label>Bottom Left Image</label>
<div class="up-mask">
<span class="file-wrapper">
<input type="file" name="Pics" class="photo" id="pics" />
<span class="button">
<span class="default-txt">Upload Photo</span>
</span>
</span>
</div><!-- .up-mask -->
<input type="hidden" name="Key" value="<?php echo $Key;?>"/>
<input type="submit" class="submit-btn" value="SAVE" />
<span class="save-notice">Your changed has been saved!</span>
</form>
如您所见, process-001.php 是处理来自 HTML 表单的所有变量的文件。但我很难“捕捉”$Headline
并$SubHeadline
通过该表单提交,实际上它也被 Ajax “操纵”......
我尝试在 process-001.php 上使用此代码:
$Headline = $_POST['Headline'];
$SubHeadline = $_POST['Sub-Headline'];
但似乎那些变量是空的......如何正确获取AJAX提交的变量?