我有这个file.html
试图在neg.php
单击图像时调用 a (有很多<p class="bagi">
.
<p class ="bagi">
<a href="try.html" onclick="return false;">
<img src="images/neg.png" title ="Rate this negative" onclick="negative(this);">
Try try try try try
</a>
</p>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
function negative(obj) {
var url = obj.parentNode.valueOf('href');
var name = obj.parentNode.innerText;
alert(url);
$("#quote p").load("neg.php?url="+ url + "&name=" + name);
}
</script>
<div id="quote"><p></p></div>
与上面的neg.php
代码位于同一文件夹中,并将文本文件写入子文件夹cat/nonstatistics
,如下所示:
<?php
header("Cache-Control: no-cache");
$url = $_GET["url"];
$name = $_GET["name"];
$file = 'cat/nonstatistics/' . $name . '.txt';
if (!file_exists($file)) {
include_once 'classifier/classifier.php';
include_once 'classifier/trainer.php';
$current = file_get_contents($url);
$current2 = strip_tags($current);
$tr = new trainer();//I use PHP text classifier in this
$arr = array('statistika', 'nonstatistika');
$tr->makeCategory($arr);
$cl = new classifier();
$text = $current2;
$result = $cl->classifyText($text);
if ($result == 'nonstatistika') {
file_put_contents($file, $current2);
echo "Rated negative, Thanks for your response!";
} else {
echo "Rating failed";
}
} else {
echo "Nice..";
}
?>
他们工作得很好,正是我想要的。但是当我将此代码转移到 Codeigniter 框架中时,我在其中放置了一个具有视图的控制器file.html
,我发现它不起作用,该功能停止在alert(url)
. 我喜欢<script type="text/javascript" src="<?php echo base_url() ?>js/jquery.js"></script>
打电话给jquery file
.
我也这样做了:
$("#quote p").load(base_url()+"views/load_hasil_cari/neg.php?url=" + url + "&name=" + name);
和这个:
$file = base_url .'views/load_hasil_cari/cat/nonstatistics/' . $name . '.txt';
他们都没有工作。我点击了图片,它所做的只是alert(url)
。
我没有做什么?谢谢..
编辑: 这是控制器文件:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Retrain extends CI_Controller {
public function Retrain() {
parent::__construct();
}
public function index() {
$this->load->model('home_model');
$data = $this->home_model->general();
$data['file']=base_url().'application/views/load_hasil_cari/neg.php';
$this->load->view('load_hasil_cari/retrain_view', $data);
}
}