Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  125] [ 3]  / answers: 1 / hits: 23298  / 11 Years ago, fri, july 12, 2013, 12:00:00

How do I extract the response content (only body) without headers?



$.ajax({ 
type: GET,
url: http://myRestservice.domain.com,
success: function(data, textStatus, request){
alert(data); //This prints the response with the header.

},
error: function(){
alert('fail');

}
});


The above code prints



HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Content-Type: text/xml; charset=utf-8
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 12 Jul 2013 20:24:06 GMT
Content-Length: 232

<?xml version=1.0 encoding=utf-8?>
<string xmlns=http://tempuri.org/>{UserID:3,RoleID:8,ActivityID:3,RoleIName:E,,Duration:10,ValidationMsg:Passed}</string>


I need to extract the value of ValidationMsg. This is a rest service call.



How do I get the response without header informations?


More From » jquery

 Answers
37

I think your server is delivering a content type that you aren't expecting.



Steps to resolve:




  • Open up the network tab in chrome's developer tools, watch the request occur and read what content type it is being delivered as. I bet, it is something like text/plain or text/html.

  • For JSON your server should be delivering it as application/json.

  • Your ajax request should specify dataType as 'json'. Normally $.ajax guesses appropriately; however, since your server is claiming it is text of some sort you are getting headers in your response.


[#77028] Thursday, July 11, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
austynp

Total Points: 505
Total Questions: 118
Total Answers: 106

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
austynp questions
;