I understand that my issue is that jQuery is trying to parse the body of the response as json, but the body is undefined, and thus throws an error.
I cannot change the response. This is the default response from Jenkins servers. It sends a 201, 404, or 500 in the header, which I would like to handle.
my ajax:
$(document).ready(function () {
$('#reviewForm').bootstrapValidator({
...stuff...
...validation...
})
.on('success.form.bv', function (e) {
// Prevent form submission
e.preventDefault();
// Get the form instance
var $form = $(e.target);
// Use Ajax to submit form data
$.ajax({
type: 'POST',
url: url+$form.serialize(),
dataType: 'text',
complete: function() {
alert("Success.");
},
error: function(xhr, status, text) {
alert("failure");
}
});
Despite a successful post (201 created), it will still hit error because of the syntax error due to the undefined body.
I would gladly handle the errors in the error: part of ajax, but I cant for the life of me figure out how to get the status code out of the header of the response.
And like I said, I would change the response if I could, but its just how Jenkins works.
Thank you.
EDIT: response header
Status Code: 201 Created
Connection: Keep-Alive
Content-Type: text/plain; charset=UTF-8
Date: Wed, 01 Oct 2014 14:51:12 GMT
Keep-Alive: timeout=15, max=100
Location: https://jenkins....
Server: Jetty(8.y.z-SNAPSHOT)
Transfer-Encoding: chunked
and this is the xhr (xml http response)
{
"readyState": 0,
"status": 0,
"statusText": "error"
}