|
Invité de passage
Inscription : juin 2010 Messages : 5 Détails du profil  Informations forums : Inscription : juin 2010 Messages : 5 Points : 3 Points : 3
|
Javascript avec Opera erreur
Bonjour,
J'ai un problème avec une de mes classes en Javascript sous Opéra, et j'Arrive pas à le résoudre, peut être que vous aurez une idée de comment y arriver, merci.
Alors, voilà le code d'erreur :
Uncaught exception: TypeError: Cannot convert 'resp' to object
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| Error thrown at line 31, column 20 in <anonymous function: onSuccess>() in http://crakpass.julien.dev.lan/script/Module/Login.js:
if(resp.success == "true")
called from line 142, column 28 in <anonymous function: request>(conf) in http://crakpass.julien.dev.lan/script/Lib/IO/Ajax.js:
config.onSuccess(this._xhr._responseText);
called from line 22, column 12 in <anonymous function: checkLogin>(conf) in http://crakpass.julien.dev.lan/script/Module/Login.js:
a.request({
called from line 57, column 20 in <anonymous function: refresh>(conf) in http://crakpass.julien.dev.lan/script/Widget/Login.js:
Crakpass.Module.Login.checkLogin();
called from line 40, column 20 in <anonymous function: refreshAll>(widget_type, params) in http://crakpass.julien.dev.lan/script/Widget.js:
this.widgets[i][j].refresh();
called from line 49, column 90 in <anonymous function>() in http://crakpass.julien.dev.lan/script/Widget.js:
Crakpass.Widget.refreshAll();
called from line 242, column 16 in <anonymous function: _wrapperFn>(e) in http://crakpass.julien.dev.lan/script/Core/Event.js:
fn.apply(_fnScope, _funcArgs); |
Voici la partie de Module.Login :
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
var a = new Ajax();
a.request({
url: 'http://crakpass.julien.dev.lan/api/login',
method: 'get',
params: {api_action: 'checkLogin'},
async: false,
onSuccess: function() {
Crakpass.Core.sleep('100');
var resp = a._xhr.responseText;
resp = Crakpass.Core.stringToJson(resp);
if(resp.success == "true")
Crakpass.Module.Login.isLogin = true;
else
Crakpass.Module.Login.isLogin = false;
//resp = null;
}
}); |
Le bout de Ajax :
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| /**
* @see http://www.w3.org/TR/XMLHttpRequest/
* @see http://msdn.microsoft.com/en-us/library/ms536752(v=vs.85).aspx
*/
request : function(conf) {
var config = conf;
/* url, method: {get,post}, content: {param1: value, param2: value}, async, onSucess, onFailure, onLoad */
if(!this.createXhr()) {
if(Crakpass.Core.isFunction(config.onFailure))
return config.onFailure("501"); // 501 - Not Implemented
else
return false;
}
/* Check parameters */
if(!Crakpass.Core.isString(config.url) || Crakpass.Core.trim(config.url) == "") {
if(Crakpass.Core.isFunction(config.onFailure))
return config.onFailure("400"); // 400 - Bad Request - The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
else
return false;
}
if(!Crakpass.Core.isString(config.method) || Crakpass.Core.trim(config.method) == "")
config.method = "GET";
else
config.method = config.method.toUpperCase();
if(!Crakpass.Core.isBoolean(config.async) || Crakpass.Core.Browser.isOpera || Crakpass.Core.Browser.isIE)
config.async = true;
// If async, configure the trigger onreadystatechange
// See http://www.quirksmode.org/blog/archives/2005/09/xmlhttp_notes_r_2.html
// see http://msdn.microsoft.com/en-us/library/cc288060(v=vs.85).aspx
if(config.async || Crakpass.Core.Browser.isIE || Crakpass.Core.Browser.isOpera) {
if(Crakpass.Core.Browser.isIE) {
if(!Crakpass.Core.isUndefined(config.onSuccess))
this._xhr.onload = config.onSuccess;
if(!Crakpass.Core.isUndefined(config.onLoad))
this._xhr.onprogress = config.onLoad;
if(!Crakpass.Core.isUndefined(config.onFailure))
this._xhr.onerror = this._xhr_ontimeout = config.onFailure;
} else {
this._xhr.onreadystatechange = function() {
alert(this.readyState);
if(this.readyState == 1 && !Crakpass.Core.isUndefined(config.onLoad) && Crakpass.Core.isFunction(config.onLoad))
config.onLoad();
if(this.readyState == 4) {
if(this.status == 200) { // Success
if(!Crakpass.Core.isUndefined(config.onSuccess) && Crakpass.Core.isFunction(config.onSuccess))
config.onSuccess(this.responseText);
} else { // Failure
if(!Crakpass.Core.isUndefined(config.onFailure) && Crakpass.Core.isFunction(config.onFailure))
config.onFailure(this.responseText);
}
}
};
}
}
if(config.method == "GET") {
// Set the url for parameters
config.url = this.setUrl(config.url, config.params);
// Open the socket
this._xhr.open(config.method, config.url, config.async);
// Send Headers
if(!Crakpass.Core.Browser.isIE)
this.setRequestHeader(config.method, config.content); // Only after open() else we have a dom error
// Send the request
this._xhr.send();
} else { // post
// construct the params to post
var params = "";
for(i in config.params) {
if(params != "")
params = params+"&";
params = params+i+"="+config.params[i];
}
// Open the socket
this._xhr.open(config.method,config.url, config.async);
// Send Headers
if(!Crakpass.Core.Browser.isIE)
this.setRequestHeader(config.method, config.content); // Only after open() else we have a dom error
// Send the request
this._xhr.send(params);
}
if(!config.async) { // Synchronous request
if(this._xhr.status == 200) {
if(!Crakpass.Core.isUndefined(config.onSuccess) && Crakpass.Core.isFunction(config.onSuccess))
config.onSuccess(this._xhr._responseText);
} else {
if(!Crakpass.Core.isUndefined(config.onFailure) && Crakpass.Core.isFunction(config.onFailure))
config.onFailure(this._xhr._responseText);
}
}
}, |
Puis, voici le code du wrapper de XMLHttpRequest pour Opera (je dois passer par un flash pour faire mon cross-domain) :
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
| /**
* @author Julien Maitrehenry <precea@precea.jp>
* @version 1.0.0
**/
/**
* @see http://www.w3.org/TR/XMLHttpRequest2/
*/
Crakpass.Core.Class({
name : "FlashXMLHttpRequest",
namespace : "Lib.IO",
inherits: Crakpass.Core.CustomEventModel,
functions : function() {
return {
_url : null,
_method : null,
_contentType : null,
_headers : new Array(),
_event : new Crakpass.Core.CustomEvent('onreadystatechange'),
me : null,
responseText : null,
readyState : 0,
status : 0,
onreadystatechange : function() {},
construct : function() {
this.me = this;
this._event.subscribe(this.onreadystatuschange);
FlashHelper.writeFlash();
},
open : function(method, url, async, user, password) {
method = method.toUpperCase();
if(method !== 'GET' && method !== 'POST')
throw "SYNTAX_ERR "+method+" is not a valid HTTP method";
this._method = method;
this._url = url;
this.readyState = 1;
this._event.fire();
},
send : function(body) {
var fs = FlashHelper.getFlash();
this.readyState = 2;
this._event.fire();
me = this;
var callback = Crakpass.uniqueId();
var t = {
parent : null,
construct : function(p) {
this.parent = p;
},
finish : function(txt) {
this.parent.finish(txt);
}
};
t.construct(this);
window[callback] = t;
fs.XmlHttp(this._url, "window['"+callback+"']['finish']", this._method, body, this.contentType, this._headers);
this.readyState = 3;
//this._event.fire();
this.status = 200;
},
setRequestHeader : function(header, value) {
if(header.toLowerCase() === "content-type") {
this._contentType = value;
}
this._headers.push(header);
this._headers.push(value);
},
finish : function(text) {
this.responseText = FlashHelper.getFlash().GetVariable(text);
this.readyState = 4;
this._event.fire();
}
}
}()
});
Crakpass.alias(Crakpass.Lib.IO.FlashXMLHttpRequest, 'FlashXMLHttpRequest');
var FlashHelper = new function() {
this.width = 0;
this.height = 0;
this.shouldWaitForFlash = function() {};
this.isFlashInstalled = function() {
var ret;
if (typeof(this.isFlashInstalledMemo) != "undefined") { return this.isFlashInstalledMemo; }
if (typeof(ActiveXObject) != "undefined") {
try {
var ieObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
} catch (e) { }
ret = (ieObj != null);
} else {
var plugin = navigator.mimeTypes["application/x-shockwave-flash"];
ret = (plugin != null) && (plugin.enabledPlugin != null);
}
this.isFlashInstalledMemo = ret;
return ret;
};
this.getFlash = function() {
while(Crakpass.Core.get("Crakpass_Lib_IO_FlashXMLHttpRequest_storage") === null || typeof Crakpass.Core.get("Crakpass_Lib_IO_FlashXMLHttpRequest_storage").ping !== "function")
return this.getFlash();
return Crakpass.Core.get("Crakpass_Lib_IO_FlashXMLHttpRequest_storage");
};
this.checkFlash = function() {
// confirm that the Flash Storage is running
try {
return (this.getFlash().ping() == "pong");
}
catch (e) { return false; }
}
this.writeFlash = function() {
if(Crakpass.Core.get("Crakpass_Lib_IO_FlashXMLHttpRequest") === null) {
div = document.createElement('div');
div.id = "Crakpass_Lib_IO_FlashXMLHttpRequest";
var swfName = "Flash4AJAX.swf";
if (window.ActiveXObject && !FlashHelper.isFlashInstalled()) {
// browser supports ActiveX
// Create object element with download URL for IE OCX
var str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
str = str + ' codebase="http://download.macromedia.com';
str = str + '/pub/shockwave/cabs/flash/swflash.cab#version=8,5,0,0"';
str = str + ' height="' + this.height + '" width="' + this.width + '" id="Crakpass_Lib_IO_FlashXMLHttpRequest_storage">';
str = str + ' <param name="movie" value="' + swfName + '">';
str = str + ' <param name="quality" value="high">';
str = str + ' <param name="swliveconnect" value="true">';
str = str + '<\/object>';
} else {
// browser supports Netscape Plugin API
var str = '<object id="Crakpass_Lib_IO_FlashXMLHttpRequest_storage" data="' + swfName + '"';
str = str + ' type="application/x-shockwave-flash"';
str = str + ' height="' + this.height + '" width="' + this.width + '">';
str = str + '<param name="movie" value="' + swfName + '">';
str = str + '<param name="quality" value="high">';
str = str + '<param name="swliveconnect" value="true">';
str = str + '<param name="pluginurl" value="http://www.macromedia.com/go/getflashplayer">';
str = str + '<param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer">';
str = str + '<p>You need Flash for this.';
str = str + ' Get the latest version from';
str = str + ' <a href="http://www.macromedia.com/software/flashplayer/">here<\/a>.';
str = str + '<\/p>';
str = str + '<\/object>';
}
div.innerHTML = str;
document.body.appendChild(div);
}
}
}; |
|