⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 service.js

📁 这是一个ajax的例子大家好好的看看就是一个鱼眼的效果
💻 JS
📖 第 1 页 / 共 2 页
字号:
if(!dojo._hasResource["dojox.rpc.tests.Service"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojox.rpc.tests.Service"] = true;dojo.provide("dojox.rpc.tests.Service");dojo.require("dojo.io.script");dojo.require("dojox.rpc.Service");dojo.require("dojox.rpc.JsonRPC");dojo.require("dojox.rpc.Rest");//this is a copy of our smd in js form, so we can just share it easily//dojo.require("dojox.rpc.tests.resources.testSmd");dojox.rpc.tests.service = new dojox.rpc.Service(dojo.moduleUrl("dojox.rpc.tests.resources", "test.smd"));doh.register("dojox.rpc.tests.echo", 	[ 		{			name: "#1 POST,URL,Named Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				//test when given named params				var td = this.svc.postEcho({message: this.name,foo:2});				td.addCallback(this, function(result){					if (result==this.name){						d.callback(true);					}else{						d.errback(new Error("Unexpected Return Value: ", result));					}				});				return d;			}		},		{			name: "#2 POST,URL,Ordered Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				//test when given named params				var td = this.svc.postEcho(this.name,2);				td.addCallback(this, function(result){					if (result==this.name){						d.callback(true);					}else{						d.errback(new Error("Unexpected Return Value: ", result));					}				});				return d;			}		},		{			name: "#3 GET,URL,Named Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				//test when given named params				var td = this.svc.getEcho({message: this.name});				td.addCallback(this, function(result){					if (result==this.name){						d.callback(true);					}else{						d.errback(new Error("Unexpected Return Value: ", result));					}				});				return d;			}		},				{			name: "#3.1 REST PUT,Named Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				res = this.name + Math.random();				//test when given named params								var td = this.svc.restStore.put({location: "res"},res);				td.addCallback(this, function(result){					var td = this.svc.restStore({location: "res"});					td.addCallback(this, function(result){						if (result==res){							d.callback(true);						}else{							d.errback(new Error("Unexpected Return Value: ", result));						}					});										});				return d;			}		},		{			name: "#3.2 REST POST,Named Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				var newRes = this.name + Math.random();				res += newRes;				//test when given named params				var td = this.svc.restStore.post({location: "res"},newRes);				td.addCallback(this, function(result){					var td = this.svc.restStore({location: "res"});					td.addCallback(this, function(result){						if (result==res){							d.callback(true);						}else{							d.errback(new Error("Unexpected Return Value: ", result));						}					});										});				return d;			}		},		{			name: "#3.3 REST DELETE,Named Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				//test when given named params				var td = this.svc.restStore['delete']({location: "res"});				td.addCallback(this, function(result){					var td = this.svc.restStore({location: "res"});					td.addCallback(this, function(result){						if (result=="deleted"){							d.callback(true);						}else{							d.errback(new Error("Unexpected Return Value: ", result));						}					});										});				return d;			}		},		{			name: "#3.4 GET,URL,Named Parameters, Returning Json",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				//test when given named params				var td = this.svc.getEchoJson({message:'{"foo":"bar"}'});				td.addCallback(this, function(result){					if (result.foo=='bar'){						d.callback(true);					}else{						d.errback(new Error("Unexpected Return Value: ", result));					}				});				return d;			}		},		{			name: "#3.5 GET,PATH,Named Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				//test when given named params				var td = this.svc.getPathEcho({path: "pathname"});				td.addCallback(this, function(result){					if (result=="/path/pathname"){						d.callback(true);					}else{						d.errback(new Error("Unexpected Return Value: ", result));					}				});				return d;			}		},		{			name: "#4 GET,URL,Ordered Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				//test when given named params				var td = this.svc.getEcho(this.name);				td.addCallback(this, function(result){					if (result==this.name){						d.callback(true);					}else{						d.errback(new Error("Unexpected Return Value: ", result));					}				});				return d;			}		},		{			name: "#5 POST,URL,Named Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				//test when given named params				var td = this.svc.postJsonEcho({message: this.name});				td.addCallback(this, function(res){					var result = dojo.fromJson(res);					if (result && result.message && result.message==this.name){						d.callback(true);					}else{						d.errback(new Error("Unexpected Return Value: ", result));					}				});				return d;			}		},		{			name: "#6 POST,JSON,Ordered Parameters",			timeout: 4000,			setUp: function(){				//this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);				this.svc = dojox.rpc.tests.service;			},			runTest: function(){				var d = new doh.Deferred();				if (window.location.protocol=="file:") {					var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");					d.errback(err);					return d;				}				//test when given named params				var td = this.svc.postJsonEcho(this.name);				td.addCallback(this, function(res){					var result = dojo.fromJson(res);					if (result && result.message && result.message==this.name){						d.callback(true);					}else{						d.errback(new Error("Unexpected Return Value: ", result));					}				});				return d;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -