简体   繁体   中英

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 Code:

$(document).ready(function(){   

    $.ajax({
    type: "GET",
    url: "Tags.php",
    dataType: "xml",
    success: function(xml) {
    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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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