DocAhrens
20 Sep 2012, 2:44 PM
I am using ExtJS 4.x, and need to send a request to a Tomcat server with a Spring backend using method POST with a JSON payload that returns a PDF to the browser. Using Google's Postman, I can send it successfully pasting the JSON object into the raw input and setting the content-type to application/json, and Accept to application/pdf, but cannot seem to get Ext to send it as JSON - it appears to be submitting the data like a form post. companyName="My Company", etc.
var payload = {
companyName: "My Company",
items: [{
id: "CTNT080352",
thumbnail: "/image/CTNT080352",
title: "My Title Here"
}],
reportCreatedDate: "September 20, 2012",
reportEndDate: "September 19, 2012",
reportStartDate: "September 01, 2012",
collection: {
id: "CTNT080352",
thumbnail: "/image/CTNT080352",
title: "My Items Collection",
total: 100,
count: 3,
rate: "3.0%"
},
name: "First Lastname",
userEmail: "admin@company.com"
};
Ext.Ajax.request({
url: '/webapp/report/pdf/sequence',
extraParams: printPayload,
method: 'POST',
headers: {
'Content-type': 'application/json',
'Accept': 'application/pdf'
},
success: function(response){
var text = response.responseText;
},
failure: function(response){
var text = response.responseText;
}
});
var payload = {
companyName: "My Company",
items: [{
id: "CTNT080352",
thumbnail: "/image/CTNT080352",
title: "My Title Here"
}],
reportCreatedDate: "September 20, 2012",
reportEndDate: "September 19, 2012",
reportStartDate: "September 01, 2012",
collection: {
id: "CTNT080352",
thumbnail: "/image/CTNT080352",
title: "My Items Collection",
total: 100,
count: 3,
rate: "3.0%"
},
name: "First Lastname",
userEmail: "admin@company.com"
};
Ext.Ajax.request({
url: '/webapp/report/pdf/sequence',
extraParams: printPayload,
method: 'POST',
headers: {
'Content-type': 'application/json',
'Accept': 'application/pdf'
},
success: function(response){
var text = response.responseText;
},
failure: function(response){
var text = response.responseText;
}
});