Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 0c73636

Browse files
author
Pat Patterson
committed
Handle apexrest payloads correctly. Fixes #49
1 parent bef9edb commit 0c73636

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

forcetk.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ if (forcetk.Client === undefined) {
380380
* @param callback function to which response will be passed
381381
* @param [error=null] function to which jqXHR will be passed in case of error
382382
* @param [method="GET"] HTTP method for call
383-
* @param [payload=null] payload for POST/PATCH etc
383+
* @param [payload=null] string or object with payload for POST/PATCH etc or params for GET
384384
* @param [paramMap={}] parameters to send as header values for POST/PATCH etc
385385
* @param [retry] specifies whether to retry on error
386386
*/
@@ -389,10 +389,28 @@ if (forcetk.Client === undefined) {
389389
var that = this,
390390
url = this.instanceUrl + '/services/apexrest' + path;
391391

392+
method = method || "GET";
393+
394+
if (method === "GET") {
395+
// Handle proxied query params correctly
396+
if (this.proxyUrl && payload) {
397+
if (typeof payload !== 'string') {
398+
payload = $.param(payload);
399+
}
400+
url += "?" + payload;
401+
payload = null;
402+
}
403+
} else {
404+
// Allow object payload for POST etc
405+
if (payload && typeof payload !== 'string') {
406+
payload = JSON.stringify(payload);
407+
}
408+
}
409+
392410
return $.ajax({
393-
type: method || "GET",
411+
type: method,
394412
async: this.asyncAjax,
395-
url: (this.proxyUrl !== null) ? this.proxyUrl : url,
413+
url: this.proxyUrl || url,
396414
contentType: 'application/json',
397415
cache: false,
398416
processData: false,

0 commit comments

Comments
 (0)