<body> <div> <h2>jquery发送ajax请求</h2> <button>GET</button> <button>POST</button> <button>通用型方法ajax</button> </div> <script> $('button').eq(0).click(function () { $.get('http://localhost:8000/jquery-server', { a: 100, b: 200 }, function (data) { console.log(data); }) }); $('button').eq(1).click(function () { $.post('http://localhost:8000/jquery-server', { a: 100, b: 200 }, function (data) { console.log(data); }) }); $('button').eq(2).click(function () { $.ajax({ url: 'http://localhost:8000/jquery-server', data: { a: 100, b: 200 }, type: 'GET', dataType: 'json', success: function (data) { console.log(data); }, error: function () { console.log("error") }
}) });
</script> </body>
|