0

I using $.ajax method in jquery to implement an ajax call on a PHP file. I want to submit 2 parameters to the PHP file which will return response as XML. This is what I am trying to do:

$.ajax({
 type: "GET",
 url: 'server.php',
 dataType: 'xml',
 data: {
  'param1' : '2',
  'param2': '3'
 },
 success: function(data) {
  alert('success');
  // do something with xml returned...
 },
 error: function(xhr, ajaxOptions, thrownError){
  alert(xhr.status);
  alert(xhr.responseText);
 }
 });

In the PHP file I've simply done this for debugging:

echo '<?xml version="1.0"?>
<a>vala</a>
<b>valb</b>';
die;

This returns an error and I receive two alerts, one says "200" and the other shows the XML shown above. What am I doing wrong?

Thanks.

0

3 Answers 3

2

Your xml output is not vaild instead of

echo '<?xml version="1.0"?>
 <a>vala</a>
 <b>valb</b>';
 die;


echo '<?xml version="1.0"?>
<root>
<a>vala</a>
<b>valb</b> 
</root>';
die;
Sign up to request clarification or add additional context in comments.

Comments

1

200 means everything is OK.

Try adding header('Content-type: text/xml'); to the top of server.php.

Comments

0

Try changing die; to exit();

Edit: my bad that's not right

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.