标签:
ajax
javascript
原创作品,允许转载,转载时请务必以超链接形式标明文章
原始出处 、作者信息和本声明。否则将追究法律责任。
http://cnn237111.blog.51cto.com/2359144/1038080
- $(function () {
- $("#btntest").click( function(){
- var s=checkodd(5);
- alert(s);
- });
- });
- function checkodd(i) {
- var options = {
- type: 'POST',
- url: "test.ashx",
- data: { "i": i },
- success: function (result) {
- if (result.code > 0) {
- return "odd";
- }
- else {
- return "even";
- }
- },
- dataType: "json",
- error: function (result) {
- alert("error");
- }
- };
- $.ajax(options);
- }
- function checkodd(i) {
- var returnvalue;
- var options = {
- type: 'POST',
- url: "test.ashx",
- data: { "i": i },
- success: function (result) {
- if (result.code > 0) {
- returnvalue = "odd";
- }
- else {
- returnvalue = "even";
- }
- },
- dataType: "json",
- error: function (result) {
- alert("error");
- }
- };
- $.ajax(options);
- return returnvalue;
- }
- function checkodd(i) {
- var returnvalue;
- var options = {
- type: 'POST',
- url: "test.ashx",
- data: { "i": i },
- async:false,
- success: function (result) {
- if (result.code > 0) {
- returnvalue = "odd";
- }
- else {
- returnvalue = "even";
- }
- },
- dataType: "json",
- error: function (result) {
- alert("error");
- }
- };
- $.ajax(options);
- return returnvalue;
- }
- function useXMLHttpRequest() {
- var xmlhttp = new XMLHttpRequest();
- xmlhttp.open("POST", "test.ashx", false);
- xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
- xmlhttp.onreadystatechange = function () {
- if (xmlhttp.readyState == 4) {
- //alert(xmlhttp.responseText);
- if (xmlhttp.responseText.code > 0) {
- alert("odd");
- }
- else {
- alert("even");
- }
- }
- };
- xmlhttp.send("i=5");
- alert("finished");
- }