Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5970203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:20:27+00:00 2026-05-22T20:20:27+00:00

I am having some difficulties with the XML dataype when using $.ajax . I

  • 0

I am having some difficulties with the XML dataype when using $.ajax.

I created a PHP file (test.php):

<script type="text/javascript" src="js/jquery.min.js"></script>

<?php        
   //this code will show some xml tag when there is an ajax call 
   if(isset($_REQUEST['t']) && $_REQUEST['t']==1){
      echo "<result >";
      echo "<info>Tristan Jun</info>";
      echo "<age>22</age>";
      echo "</result>";
      return;
    }
?>

<script>
$(document).ready(function(){
    $('#testing').click(function(){
        alert('uuuuuuu');
        var content = $.ajax({
           type:"GET",
           url :"test.php",
                   data:'t=1',
           dataType:"**html**",
           async:false,
           success:function(content){           
                cont = $(content);
                inf     = cont.find('info').text();
                age = cont.find('agel').text();
            //alert('inf');
                $('#show1').html(inf);
                $('#show2').html(total);
           },
           error: function(){
                alert('THERE'S AN ERROR');
           }
         }).**responseHTML**;
      });//end of click
 });//end of ready
 </script>

 <a id="testing" href="#">TEST</a>

 <div id="show1"></div>
 <div id="show2" style="background-color:#069"></div>

Here is my description for this example:

  • When i click the ‘TEST’ button, it will call the AJAX to show the result of the PHP code
  • In the AJAX call I only want to show the text of each tag in 2 <div> below (#show1, #show2)

The above example is using dataType HTML in $.ajax and it work well for this type. But when I tried with dataType XML, it didn’t show anything.

So, I hope you guys give me some ideas or some references about this problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:20:28+00:00Added an answer on May 22, 2026 at 8:20 pm

    If the whole code you’ve posted is the content of test.php, the response can’t be valid xml.

    The output will end with <result/> , but start’s with a <script/> .
    (XML needs to have one root-element).

    I would suggest to use the output_buffer, if the request comes via ajax discard the contents of the buffer before echoing the xml.(Or just put the PHP-code at the top )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some difficulties creating a javascript appointment style calendar. While it does render,
I'm having some difficulties parsing strings of DateTime using DateTime.ParseExact. DateTime result; CultureInfo provider
I am using a SuggestBox and I am having some difficulties to obtain the
I was having some difficulties with some text I was receiving from a Web
i'm trying to set up the selenium-maven-plugin and having some difficulties i hope somebody
We've been having some issues with a SharePoint instance in a test environment. Thankfully
I have been having some issues with LINQ-To-SQL around memory usage. I'm using it
I am having some difficulties with the simplest maven-spring app. Actually, BeanFactory does not
I'm trying to make a soap request and having difficulties. Here is my php:
I've been having some difficulties with setting the height of a listbox. Code like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.