Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

trying without jquery ajax.

add mozSystem: true in new XmlHttpRequest
  • Loading branch information...
commit 1c1237b0924113e7019e311f32ff3c1036822457 1 parent 4a5df59
@swznd swznd authored
Showing with 91 additions and 19 deletions.
  1. +91 −19 js/api.js
View
110 js/api.js
@@ -5,14 +5,35 @@ this.api = (function() {
var APIURL = 'http://localhost/projecte/api/';
function items(last,callback) {
- $.getJSON(APIURL+'event/list/?limit=10', function(json) {
- if(json.status == true) {
- callback(json.results);
- }
- else {
- callback(false);
- }
- });
+ get(APIURL+'event/list/?limit=10', function(resp) {
+ if($.isFunction(callback)) {
+ callback(resp.results);
+ }
+ },
+ function() {
+ if($.isFunction(callback)) {
+ callback(false);
+ }
+ })
+ // $.ajax({
+ // url: APIURL+'event/list/?limit=10',
+ // beforeSend: function(xhr) {
+ // xhr.mozSystem = true
+ // },
+ // dataType:'jsonp',
+ // success: function(resp) {
+ // if(resp.status == true) {
+ // if($.isFunction(callback)) {
+ // callback(resp.results);
+ // }
+ // }
+ // },
+ // error: function() {
+ // if($.isFunction(callback)) {
+ // callback(false);
+ // }
+ // }
+ // })
}
function detail(id,callback) {
@@ -55,15 +76,23 @@ this.api = (function() {
function exchangeToken(token,token_exchange,callback) {
var ret = false;
- $.post(APIURL+'user/token_exchange', {token: token, token_exchange: token_exchange }, function(resp) {
- if(resp.status) {
- ret = resp.results;
- }
-
- if($.isFunction(callback)) {
- callback(ret);
- }
- })
+ // $.ajax({
+ // url: APIURL+'user/token_exchange',
+ // dataType:'jsonp',
+ // data: 'token='+token+'&token_exchange='+token_exchange,
+ // success: function(resp) {
+ // if(resp.status == true) {
+ // if($.isFunction(callback)) {
+ // callback(resp.results);
+ // }
+ // }
+ // },
+ // error: function() {
+ // if($.isFunction(callback)) {
+ // callback(false);
+ // }
+ // }
+ // })
}
function updateProfile(data, callback) {
@@ -75,16 +104,23 @@ this.api = (function() {
}
function venuesearch(query,callback) {
+ console.log(APIURL+'venue/search?q='+query);
+
$.ajax({
url: APIURL+'venue/search?q='+query,
+ dataType: 'jsonp',
success: function(resp) {
+ console.log(resp);
if(resp.status == true) {
if($.isFunction(callback)) {
callback(resp.results);
}
}
},
- error: function() {
+ error: function(xhr,status,error) {
+ console.log(xhr.responseText);
+ console.log(status);
+ console.log(error);
if($.isFunction(callback)) {
callback(false);
}
@@ -92,6 +128,42 @@ this.api = (function() {
})
}
+ function get(url,success,error) {
+ var xhr = new XMLHttpRequest({
+ mozSystem: true
+ });
+ xhr.open('GET',url, true);
+ xhr.onload = function() {
+ console.log(xhr);
+ if(xhr.readyState == 200) {
+ success(JSON.parse(xhr.response));
+ }
+ else {
+ error(xhr.response, xhr.status);
+ }
+ }
+ xhr.onerror = function(xhr) {
+ console.log(xhr)
+ }
+ xhr.send();
+ }
+
+ function post(url,data,success,error) {
+ var xhr = new XMLHttpRequest({
+ mozSystem: true
+ });
+ xhr.open('POST', url, true);
+ xhr.onload = function() {
+ if(xhr.readyState == 200) {
+ success(JSON.parse(xhr.response));
+ }
+ else {
+ error(xhr.response, xhr.status);
+ }
+ }
+ xhr.send(data ? $.param(data) : null);
+ }
+
return {
items: items,
detail: detail,
@@ -101,4 +173,4 @@ this.api = (function() {
venuesearch: venuesearch
}
-}());
+}());
Please sign in to comment.
Something went wrong with that request. Please try again.