From eb15bd6153d01c267d1ca7c746712fe704dd3101 Mon Sep 17 00:00:00 2001 From: "scotty.b.brown@gmail.com" Date: Tue, 22 Feb 2011 09:07:17 +0000 Subject: [PATCH] #286 logic added for same domain v cross domain and execute param git-svn-id: https://beef.googlecode.com/svn/trunk@757 b87d56ec-f9c0-11de-8c8a-61c5e9addfc9 --- modules/beefjs/net.js | 55 +++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/modules/beefjs/net.js b/modules/beefjs/net.js index f0e6fd2f2..a3bc8c6db 100644 --- a/modules/beefjs/net.js +++ b/modules/beefjs/net.js @@ -101,28 +101,47 @@ beef.net = { * * @return: {Object} response: this object contains the response details */ - //TODO logic for same domain vs cross domain (cross domain get requires dataType: script) - //TODO implement execute //TODO implement post //TODO build response object and return it request_new: function(scheme, method, domain, port, path, anchor, query, timeout, execute, callback) { + + //check if same domain or cross domain + if (document.domain == domain){ + same_domain = true + }else{ + same_domain = false + } + + // process a GET request if (method.toUpperCase() == "GET"){ - $j.ajax({type: method, - dataType: "script", - url: scheme+"://"+domain+":"+port+path, - data: query+"#"+anchor, - timeout: timeout, - success: function(data, textStatus, jqXHR){ - console.log(data); - }, - error: function(jqXHR, textStatus, errorThrown){ - console.log(errorThrown); - } - }); - }else{ - //POST - console.log("POST"); - } + + //set the datatype to html if its the same domain and not set to execute + if (same_domain && !execute){ + dataType = "html" + }else{ + //otherwise set to script (either because you want to execute script or its cross domain) + dataType = "script" + } + + //build and execute request + $j.ajax({type: method, + dataType: dataType, + url: scheme+"://"+domain+":"+port+path, + data: query+"#"+anchor, + timeout: (timeout * 1000), + //function on success + success: function(data, textStatus, jqXHR){ + console.log(data); + }, + //function on failure + error: function(jqXHR, textStatus, errorThrown){ + console.log(errorThrown); + } + }); + }else{ + //POST + console.log("POST"); + } }, /**