GithubHelp home page GithubHelp logo

tocurd / apirequest Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 1.0 51 KB

ApiRequest是为了简化前端开发中遇到的复杂重复的ajax请求而开发的插件,其能够有效的帮助开发者简单快速的创建一个ajax请求。 并且ApiRequest会在请求的过程中会对用户输入的数据进行简单的前端检测处理

JavaScript 86.54% HTML 13.46%
apirequest javascript jquery api

apirequest's Introduction

ApiRequest

ApiRequest是为了简化前端开发中遇到的复杂重复的ajax请求而开发的插件,其能够有效的帮助开发者简单快速的创建一个ajax请求。
并且ApiRequest会在请求的过程中会对用户输入的数据进行简单的前端检测处理,保证发送给后端的数据是规范正确的数据(后端需同样进行数据的检测)

ApiRequest Html 结构

<div api-name='User/Login' id="api-login">
	<input type="text" api-param-name="username" value="dsadas">
	<input type="password" api-param-name="password" value="dsadas">
	<button id="js-login">登陆1</button>
	<button api-event="clickSubmit">登陆2</button>
</div>

创建ApiRequest

var ApiRequest = new ApiRequest({
	User : {
		Login : {
			url : 'login.php',
			params : {
				username : {max : 16 , min : 5 , name : '用户名'},
				password : {max : 16 , min : 5 , name : '密码'},
			}
		}
	}
} , {
	url : 'http://test.tocurd.com/',
});

直接将数据提交

$("#js-login").click(function(){
	ApiRequest.push("User/Login").then(function(reslut){
		console.log(reslut)
	} , function(data){
		console.log(data)
	});
})

对数据进行二次处理后进行提交

$("[api-event='clickSubmit']").click(function(){
	ApiRequest.push("User/Login",{
		autoCommit : false
	}).then(function(reslut){
		reslut.data.params.username = 'tocurd';

		ApiRequest.commit(reslut.data.api , reslut.data.params).then(function(data){
			console.log(data)
		}, function(data){
			console.log(data)
		})

	} , function(data){
		console.log(data)
	});
})

apirequest's People

Contributors

tocurd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

slaythia

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.