1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | $(function () { $("#btntest").click(function(){ vars=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); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | function checkodd(i) { varreturnvalue; 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); returnreturnvalue; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | function checkodd(i) { varreturnvalue; 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); returnreturnvalue; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function useXMLHttpRequest() { var xmlhttp = newXMLHttpRequest(); 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"); } |