以下是我的查询结果,该结果发布到我的地址页面。这是使用用ajax调用的php来完成的。
<div id="address-wrap">
<div id="report-address">3719 COCOPLUM CIR <br>
Unit: 3548<br>
COCONUT CREEK, FL 33063</div>
<div id="report-button">
<form action="report.html">
<input name="property-id[]" type="text" class="property-id" value="64638716">
<input name="submit" type="submit" value="View Report">
</form>
</div>
<div id="clear"></div>
</div>
<div id="address-wrap">
<div id="report-address">3927 COCOPLUM CIR <br>
Unit: 35124<br>
COCONUT CREEK, FL 33063</div>
<div id="report-button">
<form action="report.html">
<input name="property-id[]" type="text" class="property-id" value="64638744">
<input name="submit" type="submit" value="View Report">
</form>
</div>
<div id="clear"></div>
</div>
<div id="address-wrap">
<div id="report-address">3949A COCOPLUM CIR <br>
Unit: A<br>
COCONUT CREEK, FL 33063</div>
<div id="report-button">
<form action="report.html">
<input name="property-id[]" type="text" class="property-id" value="64639105">
<input name="submit" type="submit" value="View Report">
</form>
</div>
<div id="clear"></div>
</div>
<div id="address-wrap">
<div id="report-address">3949 COCOPLUM CIR <br>
Unit: 3602<br>
POMPANO BEACH, FL 33063</div>
<div id="report-button">
<form action="report.html">
<input name="property-id[]" type="text" class="property-id" value="64639106">
<input name="submit" type="submit" value="View Report">
</form>
</div>
<div id="clear"></div>
</div>
<div id="address-wrap">
<div id="report-address">3949 COCOPLUM CIR <br>
Unit: 3603<br>
COCONUT CREEK, FL 33063</div>
<div id="report-button">
<form action="report.html">
<input name="property-id[]" type="text" class="property-id" value="64639107">
<input name="submit" type="submit" value="View Report">
</form>
以下是我的报告页面上的请求。我需要从表单中获取值并将其传递给我的报告页面,以便我可以附加我的ajax请求。
<script type="text/javascript">
var property-id = $('.property-id').val();
$.ajax({
url: 'http://www.domain.com/php/reports.php',
data: '?recordID=' + property-id,
success: function(data){
$('#results').html(data);
}
});
</script>
我的主要问题是我没有从我点击的表单中获取值。它给我列表中的第一个值64638716.如何才能使它附加正确的值
先谢谢你
答案 0 :(得分:0)
试一试。
您的JavaScript中的错误很少,您的变量名称包含连字符property-id
,但我将其更改为propertyid
,不要忘记在您的代码中修改它
$(document).ready(function(e) {
$("input[type=submit]").click(function(e) {
var propertyid = $(this).prevAll("input").first().val();
//alert(propertyid);
$.ajax({
url: 'http://www.domain.com/php/reports.php',
data: '?recordID=' + propertyid,
success: function(data){
$('#results').html(data);
}
});
e.preventDefault()
return false; // prevent form from submitting
});
});