[英]PHP curl doesn't work on page that contain Ajax Script
There is a table in a web page with two filters : 网页中有一个包含两个过滤器的表格:
1. Period 1.期间
2. Segment 2.细分
When user submit the form, data will display in table. 当用户提交表格时,数据将显示在表格中。
I need to fetch the data with curl. 我需要使用curl获取数据。 But I have a problem.
但是我有一个问题。 When I try to view source, I think the data processed with Ajax.
当我尝试查看源代码时,我认为使用Ajax处理了数据。 Here is the code (from view source) :
这是代码(来自视图源):
<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>
I tried to fetch the data with PHP curl, but I failed. 我试图使用PHP curl来获取数据,但是失败了。
Here is my PHP Code : 这是我的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;
?>
The result is only show the select element (dropdown list) with my variable selected, but the table is not showing. 结果仅显示选择了我的变量的select元素(下拉列表),但未显示该表。 I don't know why.
我不知道为什么 Maybe it's because the ajax or something.
也许是因为ajax之类的东西。
Please help. 请帮忙。 Thanks.
谢谢。
The code shows that an AJAX call is being made to wbs/api_pagename.php ( with a number of query string params). 该代码显示正在对wbs / api_pagename.php进行AJAX调用(带有许多查询字符串参数)。
If you want to access the data via cURL, your script will need to perform a HTTP GET request to this script. 如果要通过cURL访问数据,则脚本将需要对此脚本执行HTTP GET请求。 Judging from the source that you posted, this script will return JSON data.
从您发布的源来看,此脚本将返回JSON数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.