From 704bfd7cb1e5c752c5f5c69acb09aad9f99ae407 Mon Sep 17 00:00:00 2001 From: rpidikiti Date: Tue, 15 Nov 2011 19:21:39 -0800 Subject: [PATCH] Fixed IE issues and also returning ajax request object as part fo invoking the method --- conf/js/structure/src/main/js/ApiInvoker.js | 38 ++++++++++----------- conf/js/templates/ResourceObject.st | 12 +++---- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/conf/js/structure/src/main/js/ApiInvoker.js b/conf/js/structure/src/main/js/ApiInvoker.js index 5a3a9c41522..5c28a9d6728 100644 --- a/conf/js/structure/src/main/js/ApiInvoker.js +++ b/conf/js/structure/src/main/js/ApiInvoker.js @@ -71,26 +71,26 @@ var ApiInvoker = new function() { this.trace("callURL = " + callURL); this.trace("responseDataType = " + responseDataType); - + var ajaxRequest = null; if (method == "GET") { - $.get(callURL, postObject, - function(response) { - ApiInvoker.fire(completionEvent, returnType, requestId, response, callback); - }, responseDataType).complete(this.showCompleteStatus).error(this.showErrorStatus); -// $.ajax({ -// url: callURL, -// data: JSON.stringify(postObject), -// type: "GET", -// dataType: "json", -// contentType: "application/json", -// success: function(response) { -// ApiInvoker.fire(completionEvent, returnType, requestId, response, callback); -// } -// }).complete(this.showCompleteStatus).error(this.showErrorStatus); + // $.get(callURL, postObject, + // function(response) { + // ApiInvoker.fire(completionEvent, returnType, requestId, response, callback); + // }, responseDataType).complete(this.showCompleteStatus).error(this.showErrorStatus); + ajaxRequest = $.ajax({ + url: callURL, + data: JSON.stringify(postObject), + type: "GET", + dataType: "jsonp", + contentType: "application/json", + success: function(response) { + ApiInvoker.fire(completionEvent, returnType, requestId, response, callback); + } + }).complete(this.showCompleteStatus).error(this.showErrorStatus); } else if (method == "POST") { this.trace("sending post"); this.trace(JSON.stringify(postObject)); - $.ajax({ + ajaxRequest = $.ajax({ url: callURL, data: JSON.stringify(postObject), type: "POST", @@ -102,7 +102,7 @@ var ApiInvoker = new function() { } }).complete(this.showCompleteStatus).error(this.showErrorStatus); } else if (method == "PUT") { - $.ajax({ + ajaxRequest = $.ajax({ url: callURL, data: JSON.stringify(postObject), type: "PUT", @@ -113,7 +113,7 @@ var ApiInvoker = new function() { } }).complete(this.showCompleteStatus).error(this.showErrorStatus); } else if (method == "DELETE") { - $.ajax({ + ajaxRequest = $.ajax({ url: callURL, data: JSON.stringify(postObject), type: "DELETE", @@ -125,7 +125,7 @@ var ApiInvoker = new function() { }).complete(this.showCompleteStatus).error(this.showErrorStatus); } - + return ajaxRequest; }, this.guid = function() { diff --git a/conf/js/templates/ResourceObject.st b/conf/js/templates/ResourceObject.st index db099bb42ac..4067917b5b4 100644 --- a/conf/js/templates/ResourceObject.st +++ b/conf/js/templates/ResourceObject.st @@ -76,26 +76,26 @@ $endif$ $if(!method.responseVoid)$ returnType = $method.returnClassName$; $endif$ - + var ajaxRequest = null; $if(method.postObject)$ $if(method.authToken)$ - ApiInvoker.invokeAPI(authToken, resourcePath, method, queryParams, postData, eventName, requestId, returnType, callback); + ajaxRequest = ApiInvoker.invokeAPI(authToken, resourcePath, method, queryParams, postData, eventName, requestId, returnType, callback); $endif$ $if(!method.authToken)$ - ApiInvoker.invokeAPI(null, resourcePath, method, queryParams, postData, eventName, requestId, returnType, callback); + ajaxRequest = ApiInvoker.invokeAPI(null, resourcePath, method, queryParams, postData, eventName, requestId, returnType, callback); $endif$ $endif$ $if(!method.postObject)$ $if(method.authToken)$ - ApiInvoker.invokeAPI(authToken, resourcePath, method, queryParams, null, eventName, requestId, returnType, callback); + ajaxRequest = ApiInvoker.invokeAPI(authToken, resourcePath, method, queryParams, null, eventName, requestId, returnType, callback); $endif$ $if(!method.authToken)$ - ApiInvoker.invokeAPI(null, resourcePath, method, queryParams, null, eventName, requestId, returnType, callback); + ajaxRequest = ApiInvoker.invokeAPI(null, resourcePath, method, queryParams, null, eventName, requestId, returnType, callback); $endif$ $endif$ - return requestId; + return {"requestId":requestId, "ajaxRequest":ajaxRequest}; } }$ }