简体   繁体   English

Ajax(jQuery)和PHP有什么问题

[英]What is the problem with Ajax (jQuery) And Php

What is the problem with Ajax (jQuery) And Php ? Ajax(jQuery)和Php有什么问题? Why my code does not work ? 为什么我的代码不起作用?

jQuery Code: jQuery代码:

$(document).ready(function(){   

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

});

Tags.php Code Tags.php代码

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

you need to 你需要

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

instead of 代替

<?xml version="1.0" encoding="UTF-8"?>

because the <? 因为<? will get interpreted by PHP and cause a syntax error. 将被PHP解释并导致语法错误。

Tags.php is not a URL. Tags.php不是URL。 You probably need a full URL: http://www.foo.com/Tags.php . 您可能需要完整的URL: http : //www.foo.com/Tags.php

You'll find using all lowercase filenames a good idea. 您会发现使用所有小写文件名都是一个好主意。

Sorry, but "My code does not work" isn't specific enough. 抱歉,“我的代码不起作用”还不够具体。 In what way does it not work? 它以什么方式不起作用? Have you tried viewing the output of Tags.php directly in the browser to see that it contains what you're expecting it to contain? 您是否尝试过直接在浏览器中查看Tags.php的输出以查看其包含的内容?

One thing to bear in mind, though, is PHP short tags causes issues with the XML preamble, because both use <? 但是要记住的一件事是,PHP短标签会导致XML前导出现问题,因为两者都使用<? to mark where they start. 标记他们从哪里开始。 Either turn short tags off, or echo() the XML preamble. 关闭短标签,或echo()XML前置码。 The first solution is the preferred one. 第一种解决方案是首选的解决方案。

Other than that, without more information, I can't help. 除此之外,没有更多信息,我无能为力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM