使用jquery和html5 post json格式数据
来源:互联网 发布:淘宝天猫京东哪个好 编辑:程序博客网 时间:2024/06/10 11:22
创建html页面引入jQuery
<!DOCTYPE HTML ><html><head> <title>Test</title>//引入3个jquery文件 <script type="text/javascript" src="jQuery/jquery-1.7.2.js"></script> <script type="text/javascript" src="jQuery/jquery.json.js"></script> <script type="text/javascript" src="jQuery/md5.js"></script></head><body ><script type="text/javascript"> $(function() { var hash =hex_md5("phoneNumber=15210943874&key=99999999");//md5加密 var dat='{"PhoneNumber":"15210943874","authKey":"'+hash+'"}'; var obj=JSON.parse(dat);// var dat='{"phoneNumber":"15210943874"}'; console.log('the post message : ',dat); $.ajax({//ajax方式post数据 url:'http://lydfanfan.bj100.com/index.php?g=Api&m=user&a=registerphone', type:'POST', data: obj, //jsonData为此次post提交时,提交的参数,你可自定义其名称 dataType:"text", timeout:10000, error:function(){alert('Error posting data');}, success:function(result){ console.log('response :',result); }//function }); });</script></body></html>
md5.js下载
json.js:
(function($) { functiontoIntegersAtLease(n) // Format integers to have at least twodigits. { return n < 10 ? '0' + n :n; } Date.prototype.toJSON =function(date) // Yes, it polutes the Date namespace, but we'llallow it here, as // it's damned usefull. { return date.getUTCFullYear() + '-' + toIntegersAtLease(date.getUTCMonth() + 1) + '-' + toIntegersAtLease(date.getUTCDate()); }; var escapeable =/["\\\x00-\x1f\x7f-\x9f]/g; var meta = { // table of charactersubstitutions '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\' } $.quoteString =function(string) // Places quotes around a string,inteligently. // If the string contains no control characters,no quote characters, and no // backslash characters, then we can safely slapsome quotes around it. // Otherwise we must also replace the offendingcharacters with safe escape // sequences. { if (escapeable.test(string)) { return '"'+ string.replace(escapeable, function (a) { var c = meta[a]; if (typeof c === 'string'){ return c; } c = a.charCodeAt(); return '\\u00' + Math.floor(c/ 16).toString(16) + (c % 16).toString(16); }) +'"' } return '"' + string + '"'; } $.toJSON = function(o,compact) { var type = typeof(o); if (type == "undefined") return"undefined"; else if (type == "number" || type =="boolean") return o +""; else if (o === null) return"null"; // Is it a string? if (type == "string") { return$.quoteString(o); } // Does it have a .toJSON function? if (type == "object"&& typeof o.toJSON =="function") returno.toJSON(compact); // Is it an array? if (type != "function"&& typeof(o.length) =="number") { var ret =[]; for (var i= 0; i < o.length; i++) { ret.push( $.toJSON(o[i],compact) ); } if(compact) return "[" + ret.join(",") +"]"; else return "[" + ret.join(", ") +"]"; } // If it's a function, we have to warnsomebody! if (type == "function") { throw newTypeError("Unable to convert object of type 'function' tojson."); } // It's probably an object, then. ret = []; for (var k in o) { varname; var type =typeof(k); if (type== "number") name = '"' + k + '"'; else if(type == "string") name =$.quoteString(k); else continue; //skip non-string or number keys val =$.toJSON(o[k], compact); if(typeof(val) != "string") { // skip non-serializablevalues continue; } if(compact) ret.push(name + ":" +val); else ret.push(name + ": " +val); } return "{" + ret.join(", ") + "}"; } $.compactJSON =function(o) { return $.toJSON(o, true); } $.evalJSON =function(src) // Evals JSON that we know to be safe. { return eval_r("(" + src + ")"); } $.secureEvalJSON =function(src) // Evals JSON in a way that is *more*secure. { var filtered = src; filtered = filtered.replace(/\\["\\\/bfnrtu]/g,'@'); filtered =filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']'); filtered =filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, ''); if (/^[\],:{}\s]*$/.test(filtered)) returneval_r("(" + src + ")"); else throw newSyntaxError("Error parsing JSON, source is not valid."); }})(jQuery);
- 使用jquery和html5 post json格式数据
- 使用jQuery发送POST,Ajax请求返回JSON格式数据
- mui post json 格式数据
- 使用jquery ajax post json数据到jersey resource
- Jquery解析Json格式数据
- JQuery 发送Json格式数据
- JQuery 发送Json格式数据
- jQuery中使用Ajax获取JSON格式数据
- jQuery中使用Ajax获取JSON格式数据
- 【jQuery】使用getJSON()方法异步加载JSON格式数据
- jQuery中使用Ajax获取JSON格式数据示例代码
- jQuery中使用Ajax获取JSON格式数据示例代码
- java(jsp/servlet )取得客户端post过来的json格式数据(jquery等)
- android 用json格式post数据
- 使用jQuery POST提交数据返回的JSON是字符串不能解析为JSON对象
- 使用jQuery POST提交数据返回的JSON是字符串不能解析为JSON对象
- 使用jQuery POST提交数据返回的JSON是字符串不能解析为JSON对象
- C# 把数据集生成为JSON格式 并在使用Jquery 获取JSON数据
- Express.js 中文入门指引手册
- Node.JS 入门
- Express 文件上传
- NODE.JS——CRYPTO 加密模块(md5)
- client提交json(nodejs)和server解析json并返回json数据(express)
- 使用jquery和html5 post json格式数据
- JSON学习
- nodejs如何动态读取文件夹下图片,并放入json数据中并显示
- express(jade或ejs)如何实现上传图片到服务器并在客户端展示(在客户端可以删除)
- node.js 文件操作
- nodejs 调用系统命令行(unzip\ls)
- nodejs如何获取apk文件的信息(zip包)
- mongoDB基础文档
- Mac OS X 安装 Homebrew