我有這樣的阿賈克斯/ jQuery代碼:如何獲取由AJAX提交的變量正確使用PHP?
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>
,你可以看到過程001.php是處理所有的文件HTML格式的變量。但我必須提交該表格,「抓」 $Headline
和$SubHeadline
困難,這實際上「操縱」阿賈克斯太...
我嘗試使用的過程001.php驗證碼:
$Headline = $_POST['Headline'];
$SubHeadline = $_POST['Sub-Headline'];
但似乎這些變量是空的......如何正確地獲取由AJAX提交的變量?
感謝兄弟,我沒有再知道我在這裏做了一些錯字...謝謝! –
歡迎,歡迎,雖然@Corbin有我10秒...和一系列與越來越有用的信息編輯;) – Ben