Login Register

after dojo update (from 1.0.2 to nightly builds version) dojo RPC doesn't work anymore

I have built a class which inherit from JasonService. Once all worked fine. now I've updated the dojo version (only with nightly builds, before I already used dojo 1.0.2) and I get an error in remote call.

my class:

dojo.require("dojo.rpc.JsonService");
dojo.require("dojo.parser");

function createRemoteClass(className) {
	return new RemoteClass("AjaxRpc.php?Class=" + className);
}

dojo.declare("RemoteClass", dojo.rpc.JsonService,
{

	callRemote: function (method, parameters) {

		var result = null;
		var error = null;
		var _this = this;

		var def = dojo.rawXhrPost({
			url: this.serviceUrl,
			postData: this.createRequest(method, parameters),
			contentType: this.contentType,
			timeout: this.timeout,
			handleAs: "json",
			sync: true,
			preventCache:this.bustCache

		});	

		def.addCallback(function(data, evt){
				result = _this.parseResults (data);
			});
		def.addErrback(function(data, evt) {
				alert ('Error in callRemote');				
				error = new Error(data.error);
				error.id = data.id;
                                console.debug(error);
			});


		return (result);
	},
....

What I get back from the server is not always a json string. (sometimes it is html) Maybe this is the problem...
so did you change something in dojo.js, which was essential for rpc function?
has anybody an idea?

I get an error: SyntaxError:

I get an error: SyntaxError: XML tag name mismatch (expected input) message=XML tag name mismatch (expected input). (line Number: 2493 - in dojo.js (dojo.js.uncompressed))
I compared both files (old dojo.js and new dojo.js). The error is in the dojo.fromJson function. before there was a try catch.
What I get back from the server is a html string.
So maybe the problem ist handleAs: "json". because it's not always json what I get back from the server...

can anybody help me please?
thanks!

if you have handleAs json

if you have handleAs json and invalid json comes back, yes, it will complain about markup tags. you can handleAs text, and dojo.eval() the response yourself in a try if youlike?

thank you dante! I could do

thank you dante!
I could do it. but how can I know if it is json in a text or if is html?
I have no idea. Once it worked because of the try/catch, so I didn't see the problem...

If the returned string

If the returned string begins with "{" I do eval. otherwise I take the result as it is. but then I get:

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLDocument.queryCommandEnabled]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://dojotoolkit/dojo/dojo.js :: anonymous :: line 1367" data: no]dojo.js (line 353)

maybe I've got to say, that the html I get back from the server is a widget (RichText- Editor), which I parse with dojo.parser.parse...

what's wrong?

dojo.require("dojo.rpc.JsonService");
dojo.require("dojo.parser");

function createRemoteClass(className) {
	return new RemoteClass("AjaxRpc.php?Class=" + className);
}

dojo.declare("RemoteClass", dojo.rpc.JsonService,
{

	callRemote: function (method, parameters) {

		var result = null;
		var error = null;
		var _this = this;
		console.debug(this.contentType);

		var def = dojo.rawXhrPost({
			url: this.serviceUrl,
			postData: this.createRequest(method, parameters),
			contentType: this.contentType,
			timeout: this.timeout,
			handleAs: "text",
			sync: true,
			preventCache:this.bustCache
		});


		def.addCallbacks(
			function(data, evt){
				var s = data.indexOf("{");
				if(s == 0){
					data = dojo.eval("("+data+")");
					result = _this.parseResults (data);
				}else{
					result = data;
				}
				console.debug(result);
			},
			function(data, evt) {
				alert ('Error in callRemote');
				error = new Error(data.error);
				error.id = data.id;
				console.debug(error);
				result = data;
			});

		return (result);
	},

I've tried the nightly build

I've tried the nightly build from today. and now it works. (the other version was from 11th february)