首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jquery不发送post数据

jquery不发送post数据
EN

Stack Overflow用户
提问于 2015-01-11 16:34:15
回答 1查看 82关注 0票数 0

我在使用jQuery将数据从1页上传到另一页时遇到了困难。这篇文章根本没有提交。我已经使用Network来检查post数据,并且我可以看到没有发送任何表单数据。但我不知道为什么。我尝试了evt.preventDefault();,如建议的here。但结果是一样的。

这是怎么回事。index.php将数据发布到referrer-Rational.php,后者更改div并运行新的查询,并在div中显示新数据。#backref是一个back按钮,它从index.php加载相同的代码,但在referrer-company.php中。目前,referrer Rational.php并没有将数据发布到referrer company.php。但是同样的代码在将数据从index.php发布到Referator-Rational.php时也是有效的。

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

我对jQuery相当陌生,所以这是我试图保持它简单,而我学习它错综复杂。

还有什么我可以尝试的建议吗?

Index.php上的代码:

代码语言:javascript
复制
$(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发布到Referator-Rational.php。

代码语言:javascript
复制
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

推荐人守则-理由

代码语言:javascript
复制
$(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-Receign.php发布到referrer company.php。

代码语言:javascript
复制
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

编辑:请求额外详细信息:

收集邮件后:

代码语言:javascript
复制
$selected = $_POST['clickthrough'];
$date_from = $_POST['ref_date_from2'];
$date_to = $_POST['ref_date_to2'];

我得到:

代码语言:javascript
复制
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

此外,第二次发布的数据有:

代码语言:javascript
复制
Content-Length:0

要替换的referrer Rational.php中的代码:

代码语言:javascript
复制
            <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
    }  
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-11 20:03:59

我不正确地映射我的div,这就是为什么没有日志返回。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27889433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档