我正在使用jQuery来获取表单的值并进行AJAX POST调用并将值发布到.php文件,该文件将值处理到db中。
每当我尝试使用alert()
进行测试时,如果我得到了值,那么一切都有效,除了股票价值......我找不到我做错了什么..
jQuery的:
var title = $("#title").val();
var text = $("#text").val();
var summary = $("#description").val();
var keywords = $("#keywords").val();
var price = $("#price").val();
var stock = $("#stock").val();
var brand = $("#brand").val();
var product = product;
alert(title);
alert(stock);
表格:
<form class="form-horizontal form-inline">
<div class="form-group">
<label class="control-label col-sm-3" for="title">Product:</label>
<input type="text" class="form-control" id="title" name="title" placeholder="Enter new title">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="price">Price:</label>
<input type="text" class="form-control" id="price" name="price" placeholder="Enter new price">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="stock">Stock:</label>
<input type="text" class="form-control" id="stock" name="stock" placeholder="Enter new stock">
</div>
<div class='form-group'>
<label class="control-label col-sm-3" for="text">Text:</label>
<textarea class='form-control' rows='5' id='text' name='text' placeholder='Enter new text'></textarea>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="description">Description:</label>
<input type="text" class="form-control" id="description" name="description" placeholder="Enter new description">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="brand">Brand:</label>
<input type="text" class="form-control" id="brand" name="brand" placeholder="Enter new brand">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="keywords">Keywords:</label>
<input type="text" class="form-control" id="keywords" name="keywords" placeholder="Enter new keywords">
</div>
<a href="#" id="updateProductRecord" pid="<?php echo $pro_id; ?>"><button type="submit" id="submitUpdateProduct" class="btn btn-default">Submit</button></a>
</form>
答案 0 :(得分:1)
<form class="form-horizontal form-inline">
<div class="form-group">
<label class="control-label col-sm-3" for="title">Product:</label>
<input type="text" class="form-control" id="title" name="title" value="1" placeholder="Enter new title">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="price">Price:</label>
<input type="text" class="form-control" id="price" name="price" placeholder="Enter new price">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="stock">Stock:</label>
<input type="text" class="form-control" id="stock" name="stock" value="2" placeholder="Enter new stock">
</div>
<div class='form-group'>
<label class="control-label col-sm-3" for="text">Text:</label>
<textarea class='form-control' rows='5' id='text' name='text' placeholder='Enter new text'></textarea>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="description">Description:</label>
<input type="text" class="form-control" id="description" name="description" placeholder="Enter new description">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="brand">Brand:</label>
<input type="text" class="form-control" id="brand" name="brand" placeholder="Enter new brand">
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="keywords">Keywords:</label>
<input type="text" class="form-control" id="keywords" name="keywords" placeholder="Enter new keywords">
</div>
<a href="#" id="updateProductRecord" pid="<?php echo $pro_id; ?>"><button type="submit" id="submitUpdateProduct" class="btn btn-default">Submit</button></a>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
var title = $("#title").val();
var text = $("#text").val();
var summary = $("#description").val();
var keywords = $("#keywords").val();
var price = $("#price").val();
var stock = $("#stock").val();
var brand = $("#brand").val();
var product = product;
alert(title);
alert(stock);
</script>
&#13;
此代码工作正常,我认为你没有从php / ajax获得价值..