i have 2 file.
file one.php:
<?php
include 'config/dbconnect.php';
$query = mysql_query("select * from getgift_logs where status = 1") or die(mysql_error());
echo("<table border='1'>");
echo("<tr>");
echo("<td>User ID</td>");
echo("<td>Yes</td>");
echo("</tr>");
while ($row = mysql_fetch_array($query)) {
echo("<tr>");
echo("<td>".$row['user_id']."</td>");
echo "<td><button class='yes' gift_id = '".$row['id']."'>Yes</button></td>";
echo("</tr>");
}
echo("</table>");
?>
<div id='result'></div>
<script type = "text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$('.yes').click(function() {
var trans_id=$(this).attr("gift_id");
$.ajax({
url : "process.php?id="+trans_id,
type: "GET",
success: function(result) {
$('#result').html(result);
},
});
});
</script>
文件 one.php 发送了一个get请求到文件 process.php。这是文件 process.php 的内容:
<?php
include("config/dbconnect.php");
date_default_timezone_set("UTC");
$id = $_POST['trans_id'];
$query = mysql_query("select * from getgift_logs where id = '".$id."'");
$row = mysql_fetch_array($query);
$topuplink = $row['topuplink'];
$trans_id = $row['trans_id'];
$clientsecret = $row['clientsecret'];
$accesstoken = $row['accesstoken'];
$lost_money = $row['lost_money'];
$status = $row['description'];
$time = date('Ymdhis',time());
$sign = md5($money."|".$trans_id."|".$time."|".$clientsecret);
$ch = curl_init();
$data = array(
'topup_money' => $lost_money,
'reference_trans_id' => $trans_id,
'description'=>$status,
'request_time'=> $time,
'sign'=>$sign
);
$postvars = '';
foreach($data as $key=>$value) {
$postvars .= $key . "=" . $value . "&";
}
$url = $topuplink."".$accesstoken;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
print_r($response);
curl_close ($ch);
?>
在 process.php 文件中,我发送了一个POST请求,但它没能工作(未将数据发送到服务器)。
我不知道哪里出错了?请帮我!感谢所有人!
GET
请求,而不是POST
请求,或者我理解有误吗?type: "GET"
。 - chris85print_r($response)
返回{""data":null""}
。 - mrdragonvar_dump(curl_error($ch));
与curl_errno
结合使用。 - AddWeb Solution Pvt Ltd