English 中文(简体)
Ajax(jQuery)和Php有什么问题
原标题:What is the problem with Ajax (jQuery) And Php

What is the problem with Ajax (jQuery) And Php ? Why my code does not work ?

jQuery代码:

$(document).ready(function(){   

    $.ajax({
    type: "GET",
    url: "Tags.php",
    dataType: "xml",
    success: function(xml) {
    alert("success");
    }
    }); 

});

Tags.php代码

<?xml version="1.0" encoding="UTF-8"?>
<tages>
<?php echo "<tag>hello</tag>"; ?>
</tages>
问题回答

你需要

<代码><;?php回声<;?xml版本=“1.0”编码=“UTF-8”>>

而不是

<代码><;?xml版本=“1.0”编码=“UTF-8”>

因为<将被PHP解释并导致语法错误。

Tags.php不是URL。您可能需要一个完整的URL:http://www.foo.com/Tags.php

你会发现使用所有小写的文件名是个好主意。

很抱歉,“我的代码不起作用”不够具体。它在什么方面不起作用?您是否尝试过直接在浏览器中查看Tags.php的输出,以查看它是否包含您期望的内容?

不过,需要记住的一点是,PHP短标记会导致XML前导码出现问题,因为两者都使用<来标记它们的起始位置。关闭短标记,或者echo()XML前导码。第一种解决方案是首选方案。

除此之外,如果没有更多的信息,我也无能为力。





相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签