Home  >  Article  >  Backend Development  >  php怎么响应ajax

php怎么响应ajax

WBOY
WBOYOriginal
2016-06-13 13:51:48823browse

php如何响应ajax
我用ajax发送到php页面上一个请求。。。如下:

JScript code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
function refreshGoodsCat() o

在php处理,返回得到的响应内容,这个响应的内容要如何发送给ajax.
我想在ajax里面用xmlHttp.responseText接收

------解决方案--------------------
在php页面里直接echo xml or json字符串,客户端收到后解析xml or json, xml可以使用msxml组件解析,json可以下载json2.js解析。不过我建议ajax还是使用jquery提供的ajax函数,可以支持多浏览器,php使用json,php支持json。
我写过一个类似.net ICallbackEventHandler的小框架,需要我可以发给你,基于jquery and json2.
------解决方案--------------------
相应的页面根据条件返回内容:

PHP code
if($have){
    echo "1";
    exit(); <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn