Skip to content

Commit

Permalink
Handle apexrest payloads correctly. Fixes developerforce#49
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Patterson committed Oct 26, 2015
1 parent bef9edb commit 0c73636
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions forcetk.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
* @param [method="GET"] HTTP method for call
* @param [payload=null] payload for POST/PATCH etc
* @param [payload=null] string or object with payload for POST/PATCH etc or params for GET
* @param [paramMap={}] parameters to send as header values for POST/PATCH etc
* @param [retry] specifies whether to retry on error
*/
Expand All @@ -389,10 +389,28 @@ if (forcetk.Client === undefined) {
var that = this,
url = this.instanceUrl + '/services/apexrest' + path;

method = method || "GET";

if (method === "GET") {
// Handle proxied query params correctly
if (this.proxyUrl && payload) {
if (typeof payload !== 'string') {
payload = $.param(payload);
}
url += "?" + payload;
payload = null;
}
} else {
// Allow object payload for POST etc
if (payload && typeof payload !== 'string') {
payload = JSON.stringify(payload);
}
}

return $.ajax({
type: method || "GET",
type: method,
async: this.asyncAjax,
url: (this.proxyUrl !== null) ? this.proxyUrl : url,
url: this.proxyUrl || url,
contentType: 'application/json',
cache: false,
processData: false,
Expand Down

0 comments on commit 0c73636

Please sign in to comment.