问题是,POST 似乎没有向 PHP 脚本发送信息。firebug 控制台显示信息是从 JavaScript 传递的,并且格式似乎正确,但我没有得到响应,PHP 脚本也没有运行。
然而,PHP 本身运行良好。
jQuery:
$(function(){
$('#submit-item').live("click",function(){
var productName = $(".add-item-form #productName").val();
var category = $(".add-item-form #categorySelect").val();
var brandName = $(".add-item-form #brandName").val();
var volume = $(".add-item-form #volumeType").val();
$.post("addNewProduct.php",{productName:productName ,category: category, brandName: brandName, volume: volume});
});
});
和 HTML 表单:
<section id="add-item-pane" class="secondary">
<header>
<h1>add item</h1>
<a href="#" class="close-secondary"></a>
</header>
<form class="add-item-form" method="POST" action="" accept-charset=utf-8>
<div class="input">
<label for="productName">product name</label>
<input type="text" name="productName" id="productName" placeholder="Product Name">
</div>
<div class="input">
<label for="categorySelect" required>category</label>
<select name="categorySelect" id="categorySelect" placeholder="Category" required>
<option value="1">ATERIA-AINEKSET JA KASTIKKEET</option>
</select>
</div>
<div class="input">
<label for="brandName">brand name</label>
<input type="text" name="brandName" id="brandName" placeholder="Brand Name">
</div>
<div class="input">
<label for="volumeType">volume type</label>
<label for="volumeTypeKG">g/kg</label>
<input type="radio" name="volumeType" id="volumeType" value="1">
<label for="volumeTypeL">ml/l</label>
<input type="radio" name="volumeType" id="volumeType" value="2">
</div>
<input type="submit" value="Add it" id="submit-item">
</form>
</section>
接收PHP:
$productName = $_POST['productName'];
$categoryId = $_POST['category'];
$brandId = $_POST['brandName'];
$volumeId = $_POST['volume'];