开发者

What is the problem with Ajax (jQuery) And Php

开发者 https://www.devze.com 2023-01-20 02:08 出处:网络
What is the problem with Ajax (jQuery) And Php ? Why my code does not work ? jQuery Code: $(document).ready(function(){

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

jQuery Code:

$(document).ready(function(){   

    $.ajax({
    type: "GET",
    url: "Tags.php",
    dataType: "xml",
    success: function(xml)开发者_Python百科 {
    alert("success");
    }
    }); 

});

Tags.php Code

<?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.


Tags.php is not a URL. You probably need a full 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?

One thing to bear in mind, though, is PHP short tags causes issues with the XML preamble, because both use <? to mark where they start. Either turn short tags off, or echo() the XML preamble. The first solution is the preferred one.

Other than that, without more information, I can't help.

0

精彩评论

暂无评论...
验证码 换一张
取 消