jquery不发送post数据
我无法使用jQuery将数据从一个页面发布到另一个页面。这篇文章根本没有提交。我已经使用网络选项卡来检查post数据,我可以看到没有发送表单数据。但我不知道为什么。我试过evt;正如建议的那样。但结果是一样的 这是怎么回事。index.php将数据发布到referer-reason.php,从而更改div并运行新查询,并在div中显示新数据。backref是一个back按钮,它从index.php加载相同的代码,但在referer-company.php中加载。目前referer-reason.php没有将数据发布到referer-company.php。但是,在将数据从index.php发布到referer-reason.php时,同样的代码也会起作用jquery不发送post数据,jquery,post,Jquery,Post,我无法使用jQuery将数据从一个页面发布到另一个页面。这篇文章根本没有提交。我已经使用网络选项卡来检查post数据,我可以看到没有发送表单数据。但我不知道为什么。我试过evt;正如建议的那样。但结果是一样的 这是怎么回事。index.php将数据发布到referer-reason.php,从而更改div并运行新查询,并在div中显示新数据。backref是一个back按钮,它从index.php加载相同的代码,但在referer-company.php中加载。目前referer-reason.
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
它抛出了一个200 OK,但post数据中没有实际内容,如下面所示
我对jQuery还相当陌生,所以这是我在复杂地学习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发布到referer-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);
});
});
});
将数据从referer-reason.php发布到referer-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
编辑:需要额外的详细信息:
收到邮件后:
$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
正在替换的referer-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
}
我错误地映射了我的div,这就是为什么没有日志返回的原因。可以看到数据已发送,状态为200。更详细地解释这个问题detail@charlietfl根据请求添加了额外的详细信息不确定为什么它不发送数据。将尝试使用var companyId隔离变量,这有时会导致ISSE,忽略var是一种非常糟糕的做法。否则,请将日志记录到控制台和/或设置断点,以查看clcik处理程序中发生的情况。可能响应中没有正确设置值,或者ID不正确。。。不确定,没有直接访问DOMDIN,我没想到会是这样,只是我注意到一个坏习惯发生在我们所有人身上。不过,下一次我们将更好地掌握如何构建一个更容易理解的问题……祝你好运