jquery 没有发送 post 数据
jquery no sending post data
我在使用 jQuery 从一页到另一页 post 处理数据时遇到问题。 post 根本没有提交。我使用网络选项卡检查了 post 数据,我可以看到没有发送任何表单数据。但我不知道为什么。我按照建议 here 尝试了 evt.preventDefault();
。但是结果是一样的
那么这是如何工作的。 index.php posts 数据到 referrer-reason.php 更改 div 并运行新查询并在 div 中显示新数据。 #backref 是一个后退按钮,它从 index.php 但在 referrer-company.php 中加载相同的代码。目前 referrer-reason.php 没有 post 向 referrer-company.php 发送数据。但是当 post 将数据从 index.php 发送到 referrer-reason.php.
时,相同的代码可以工作
它返回 200 OK 但 post 数据中没有实际内容,如下所示。
我对 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);
});
});
});
POST 数据从 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);
});
});
});
POST 从推荐人-reason.php 到推荐人-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
另外第二个post数据有:
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
}
我错误地映射了我的 div,这就是没有返回日志的原因。
我在使用 jQuery 从一页到另一页 post 处理数据时遇到问题。 post 根本没有提交。我使用网络选项卡检查了 post 数据,我可以看到没有发送任何表单数据。但我不知道为什么。我按照建议 here 尝试了 evt.preventDefault();
。但是结果是一样的
那么这是如何工作的。 index.php posts 数据到 referrer-reason.php 更改 div 并运行新查询并在 div 中显示新数据。 #backref 是一个后退按钮,它从 index.php 但在 referrer-company.php 中加载相同的代码。目前 referrer-reason.php 没有 post 向 referrer-company.php 发送数据。但是当 post 将数据从 index.php 发送到 referrer-reason.php.
时,相同的代码可以工作它返回 200 OK 但 post 数据中没有实际内容,如下所示。
我对 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);
});
});
});
POST 数据从 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);
});
});
});
POST 从推荐人-reason.php 到推荐人-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
另外第二个post数据有:
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
}
我错误地映射了我的 div,这就是没有返回日志的原因。