duanchen7703 2013-03-06 20:10
浏览 70

ajax请求返回html,而不是实际值 - PHP

I'm using this simple PHP framework, after some upsets with others Custom PHP

I have the following controller:

<?php

class TestController extends BaseController
{

    public function __construct($action, $urlValues) {
        parent::__construct($action, $urlValues);
    }

    public function deploy_test() {
        echo json_encode("helloworld");
    }
}
?>

That function is activated by a .js function called test():

function test()
{

    var data = {
        config   : $("#config").val(),
        machines : $("#machines").val(),
        test     : $("#test").val(),
        product  : $("#product").val(),
    };

    $.post('./index.php/test/deploy_test/', data, 
    function( answer ){
        create_bar();
        console.log( answer );
    });
}

However, what I get back is the index.php page, the html itself, not the "helloworld" string as expected. I have no idea what's going on. May someone please me? The output is:

<!DOCTYPE html>
<html>
<head>
<title>Deployer</title>
</head>
<body>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  • 写回答

2条回答 默认 最新

  • doudiao2335 2013-03-06 20:13
    关注

    Specify the return type in your POST in JS: dataType: json

    http://api.jquery.com/jQuery.post/

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化