jquery不发送帖子数据

时间:2015-01-11 16:34:16

标签: jquery post

我无法使用jQuery从1页发布数据到另一页。该帖子根本没有提交。我使用网络选项卡检查发布数据,我可以看到没有发送任何表单数据。但我不明白为什么。我按照建议here尝试evt.preventDefault();。但结果是一样的。

这是怎么回事。 index.php将数据发布到referrer-reason.php,它会更改div并运行新查询并在div中显示新数据。 #backref是一个后退按钮,它从index.php加载相同的代码,但是在referrer-company.php中。目前,referrer-reason.php不会将数据发布到referrer-company.php。但是,当将数据从index.php发布到referrer-reason.php时,相同的代码也可以工作。

它会在帖子数据中返回200 OK但没有实际内容,如下所示。

我是jQuery的新手,所以这是我试图让它变得简单而我错综复杂地学习它。

关于我还能尝试什么的任何建议?

index.php上的代码:

$(document).ready(function () {
$('.clickthrough2').click(function () {
    companyId = $(this).attr('id'); 

    $.post('./ajax/referrer-reason.php', {
        clickthrough: $('#company-'+companyId+' .clickthrough').val(),
        ref_date_from2: $('#company-'+companyId+' .ref_date_from2').val(),
        ref_date_to2: $('#company-'+companyId+' .ref_date_to2').val()
    },
    function (data) {
        $('#declined2').html(data);
    });
});     
});

将数据从index.php发布到referrer-reason.php。

Remote Address:IP:80
Request URL:http://www.domain.com/sections/dash/ajax/referrer-reason.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:65
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:PHPSESSID=****
Host:www.domain.com
Origin:http://www.domain.com
Referer:http://www.domain.com/sections/dash/index.php
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
clickthrough:84
ref_date_from2:1354320000
ref_date_to2:1420934400
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:close
Content-Type:text/html; charset=UTF-8
Date:Sun, 11 Jan 2015 15:46:23 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:Apache/2.2.15 (CentOS)
Transfer-Encoding:chunked
X-Powered-By:PHP/5.4.33

引荐来源原因的代码

$(document).ready(function () {
$('#backref').click(function () {
    companyId = $(this).attr('id'); 
    $.post('./ajax/referrer-company.php', {
        clickthrough: $('#company-'+companyId+' .clickthrough').val(),
        ref_date_from2: $('#company-'+companyId+' .ref_date_from2').val(),
        ref_date_to2: $('#company-'+companyId+' .ref_date_to2').val()
    },
    function (data) {
        $('#declined2').html(data);
    });
});     
});

将来自referrer-reason.php的POST数据发送至referrer-company.php。

Remote Address:IP:80
Request URL:http://www.domain.com/sections/dash/ajax/referrer-company.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Connection:keep-alive
Content-Length:0
Cookie:PHPSESSID=****
Host:www.domain.com
Origin:http://www.domain.com
Referer:http://www.domain.com/sections/dash/index.php
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
X-Requested-With:XMLHttpRequest
Response Headersview source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:close
Content-Type:text/html; charset=UTF-8
Date:Sun, 11 Jan 2015 15:46:29 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:Apache/2.2.15 (CentOS)
Transfer-Encoding:chunked
X-Powered-By:PHP/5.4.33

编辑:要求提供更多详细信息:

收集POST后:

$selected = $_POST['clickthrough'];
$date_from = $_POST['ref_date_from2'];
$date_to = $_POST['ref_date_to2'];

我明白了:

PHP Notice:  Undefined index: clickthrough in /var/www/clients/client1/web51/web/sections/dash/ajax/referrer-company.php on line 35, referer: http://www.domain.com/sections/dash/index.php
PHP Notice:  Undefined index: ref_date_from2 in /var/www/clients/client1/web51/web/sections/dash/ajax/referrer-company.php on line 36, referer: http://www.domain.com/sections/dash/index.php
PHP Notice:  Undefined index: ref_date_to2 in /var/www/clients/client1/web51/web/sections/dash/ajax/referrer-company.php on line 37, referer: http://www.domain.com/sections/dash/index.php

第二篇帖子数据也有:

Content-Length:0

来自referrer-reason.php的代码正在被替换:

            <div id="declined2" class="declined4">
                <h4>Declined Quote <br />Reasons</h4>
                <div class="statgrid">
<?php
    $result = $mysqli->query($quotes_q);    
    while ($row = $result->fetch_array()) {
?>
                <div id="company-<?php echo $row['company_id'];?>">
                    <input type="hidden" class="ref_date_from2" value="<?php echo $date_from; ?>" />
                    <input type="hidden" class="ref_date_to2" value="<?php echo $date_to; ?>" />
                    <input type="hidden" class="clickthrough" value="<?php echo $row['company_id'] ?>" />
                        <a><div id="<?php echo $row['company_id'];?>" class="clickthrough2 col-5-6"><?php echo $row['decline_reason']; ?></div></a>
                    <div class="col-1-6"><?php echo $row['company_id_count']; ?></div>  
                </div>
<?php
    }  

1 个答案:

答案 0 :(得分:0)

我错误地映射了我的div,这就是没有日志回来的原因。