0

Can anyone tell me what I am doing wrong in the below code. I want to Ajax an xml (either text/xml or application/xml) into my REST service (same app server).

When doing that I am getting error code 400 Bad Request.

$.ajax({ type: 'POST',
     url: '<url>',
     data: '<?xml version="1.0" encoding="UTF-8"?><test>Hello World</test>',
     contentType: 'text/xml',
     dataType: 'xml',
     processData: false,
     cache: false,
     error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status +' '+thrownError);
     },
     success: function(xml) {
        alert('it works: '+xml);
     }
});

Any help would be much appreciated.

2
  • 1
    A 400 error doesn't occur via Javascript, it occurs on the server. You should specify what server side technology you are using post the relevant code. Commented Feb 19, 2013 at 16:05
  • @Ek0nomik You are right. It was a problem with my REST service it seems. If you want to add your response as an answer I will accept it. Thanks Commented Feb 19, 2013 at 16:31

3 Answers 3

3

Are you actually calling your server with the relative URL url: '<url>',? That might be a big problem. This is a really Bad Request..

http://yourserver.com/<url>

Your code should instead be:

url: '/myrestservicepath',
Sign up to request clarification or add additional context in comments.

Comments

1

A 400 error doesn't occur via Javascript, it occurs on the server. You should specify what server side technology you are using and post the relevant code. Robert Fricke's answer might shed some light on the server side issue.

Comments

0

The URL that you provide to the .ajax call is a relative path so you will need to be careful and make sure yo uare passing in the right value

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.