0

以下是我的查询结果,该查询已发布到我的地址页面。这是使用 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。我怎样才能让它附加正确的值

先感谢您

4

1 回答 1

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
    });    
});
于 2013-05-18T23:05:07.430 回答