jquery post php返回html,jquery post返回整个html页面代码(jquery post return whole html page code)...

I'm not sure how you thing works or even what it should do, but something I usually do when i use $.post (or ajax) is that I add an extra parameter (ajax=1) in the post data so that i can know and do only the echo I want when its an ajax call. So basicly, on server side, it could look like this:

if (isset($_POST['ajax']) && $_POST['ajax']) {

echo json_encode($anArray);

die()

}

The die() function prevent the rest of the page to be echoed. This is quite usefull because you can create a file (we'll call this inc.ajax.php) which is included BEFORE ANY CODE IS ECHOED (let's say in header or first line in index.php, whatever) and you can use it as a controller. So you could add an operator, and inc.ajax.php would become your ajax controller. Taking back previous example:

if (isset($_POST['ajax']) && $_POST['ajax']) {

$operator = $_POST['operator'];

switch ($operator) {

case 'upload':

$obj->upload();

echo json_encode($obj,true);

break;

default:

echo json_encode($anArray);

break;

}

die()

}

If inc.ajax is included in every page (on the index.php perhaps), it is easy to $.post() on the current url with ajax=1&operator=[your operator] and you'll always get the json you need (or response could still be html. In one operator, you could for example echo an entire template and then "die()" so that you just get the one portion of the website that you want.) Hope this helps, hope i didn't miss the point and surely hope i didn't confuse you with all that stuff!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值