【发布时间】:2015-11-25 09:35:18
【问题描述】:
网页中有一个带有两个过滤器的表格:
1.期间
2. 细分
当用户提交表单时,数据将显示在表格中。
我需要使用 curl 获取数据。但我有一个问题。当我尝试查看源代码时,我认为数据是用 Ajax 处理的。这是代码(来自查看源代码):
<script type="text/javascript">
function addRow( obj1, lvl, kws, wtl, kndt, cmdf, csss ) {
$.ajaxSetup ({
cache: false
});
$.ajax({
url : "wbs/api_pagename.php?lvl=" + ( parseInt( lvl ) + 1 ) + "&kws=" + kws + "&wtl=" + wtl + "&dtl=" + kndt + "&periode=" + g_periode + "&segmen=" + g_segmen,
dataType: 'json',
beforeSend:function(){
progshow();
},
success:function( data, textStatus, jqXHR ){
var tbl = document.getElementById('tbl_1');
temprow = document.getElementById( obj1 ).rowIndex;
lvl++;
for ( var i in data ){
temprow++;
var mainRow = tbl.insertRow( temprow );
var trId = obj1 + "_" + i;
mainRow.id = trId;
if (csss.length > 0) {
csss += ' ';
}
csss += "css_" + obj1;
mainRow.className = csss;
var newCell = mainRow.insertCell( 0 );
newCell.innerHTML = '';
var newCell = mainRow.insertCell( 1 );
newCell.innerHTML = '';
for ( _i = 1; _i < lvl - 1; _i++ ) {
newCell.innerHTML += ' ';
}
if (lvl <= 2) {
newCell.innerHTML += "<a href=\"javascript:doMenu('" + trId + "','" + lvl + "','" + data[i][0] + "','" + data[i][1] + "','" + data[i][2] + "','','" + csss + "');\" id='a" + trId + "'>[+]";
}
newCell.innerHTML += data[i][ 2 + parseInt( lvl ) ];
addrow1( mainRow, data, i, 1 );
}
proghide();
},
error : function( jqXHR, textStatus, errorThrown ){
alert(jqXHR.status);
alert(textStatus);
alert(errorThrown);
}
});
}
</script>
我尝试使用 PHP curl 获取数据,但失败了。
这是我的 PHP 代码:
<?php
$kipas1 = "entered_user=XXXXX&entered_password=XYZXYZ&login=login&redirect_to=wp-admin/";
$cr = curl_init();
curl_setopt( $cr, CURLOPT_URL, "http://webpage.com/index.php" );
curl_setopt( $cr, CURLOPT_CONNECTTIMEOUT, 3000 );
curl_setopt( $cr, CURLOPT_USERAGENT, "Mozilla/7.0 (compatible; MSIE 9.0; Windows NT 5.1)" );
curl_setopt( $cr, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $cr, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $cr, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $cr, CURLOPT_POST, true );
curl_setopt( $cr, CURLOPT_POSTFIELDS, $kipas1 );
curl_setopt( $cr, CURLOPT_COOKIESESSION, true );
curl_setopt( $cr, CURLOPT_COOKIEJAR, 'C:\xampp\htdocs\coc\cookie.txt' );
$whoCares = curl_exec( $cr );
$myvars = "lvl=2&kws=ALL&wtl=ALL&dtl=ALL&periode=201511&segmen=ALL";
curl_setopt( $cr, CURLOPT_URL, "http://webpage.com/target.php" );
curl_setopt( $cr, CURLOPT_POST, 1 );
curl_setopt( $cr, CURLOPT_POSTFIELDS, $myvars );
curl_setopt( $cr, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $cr, CURLOPT_HEADER, 0 );
curl_setopt( $cr, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec( $cr );
echo $result;
?>
结果仅显示选择了我的变量的选择元素(下拉列表),但表格未显示。我不知道为什么。也许是因为ajax什么的。
请帮忙。谢谢。
【问题讨论】:
-
你必须像 ajax 从那里获取数据一样为
wbs/api_pagename.php卷曲。 -
检查错误
error_reporting(E_ALL); -
好的。我会尝试。谢谢
标签: javascript php ajax curl