jQuery和javascript函数不能用于curl

时间:2015-10-26 11:34:51

标签: javascript php jquery curl

我使用curlphp在我的网站上加载页面,所有内容都正常,但我使用的是java scriptjQuery在那个页面不起作用。任何人都能说出原因和解决方案吗? 这是我用来将内容调用到我的页面的代码

$c = curl_init("path/to/page.php");
 curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
 $contents = curl_exec($c);
 if (curl_error($c))
 die(curl_error($c));
 $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
 curl_close($c);

这是我使用的page.php

<h1>Demo 3 - Cat picture.</h1>
 <p>
  You\'ll see that along with the URL and container content, the title has also been updated.
  Using PJAX you can even give pages custom titles, for example

  <a href="page2.php" data-title="Custom title!">this link</a>
   will open page 2  with the title "Custom title!".
 </p>
 <hr/>
 <h3>A picture of a cat.</h3>
 <img src="img/cat.jpg" alt="Picture of a drunk cat" />
 <p>There really isn\'t a good reason for this...</p>
 <script>
 alert("success");
 </script>

除了我提供的提醒

之外,所有内容都会显示

main_page.php

<?php
$title = 'Page 3 - Cat';
$c = curl_init('path/to/page.php');
 curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
 $contents = curl_exec($c);
 if (curl_error($c))
 die(curl_error($c));
 $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
 curl_close($c);
if(isset($_SERVER['HTTP_X_PJAX']) && $_SERVER['HTTP_X_PJAX'] == 'true'){
 echo $contents;
 echo "<title>{$title}</title>";
}else{
 include 'wrapper.php';
}
?>

0 个答案:

没有答案