阿贾克斯教程后,获得 [英] Ajax tutorial for post and get

查看:165
本文介绍了阿贾克斯教程后,获得的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个简单的Ajax教程或案例研究一个简单的输入表单,在这里我想通过一个输入表单,它发送到数据库,并与结果答复后一个用户名。
对于这样的教程任何建议是值得欢迎的,因为我用Mootool只得到了一个,但我使用jQuery寻找一个!

I need a simple ajax tutorial or case study for a simple input form, where I want to post a username through an input form, which sends it to the database and replies with the results.
Any recommendation for such tutorial is welcome, because I've only got one using Mootool but I'm searching for one using jQuery!

推荐答案

你可以试试这个:

$.ajax({
  url: "test.html",
  cache: false,
  success: function(html){
    $("#results").append(html);
  }
});

在code将追加的test.html 文件到 #results 元素

找到更多的jQuery的网站: http://api.jquery.com/jQuery.ajax/

find more at jquery website: http://api.jquery.com/jQuery.ajax/

更新: 用它来发送POST数据,并输出结果

update: use this to send POST data and output result

var menuId = $("ul.nav").first().attr("id");
var request = $.ajax({
  url: "script.php",
  type: "POST",
  data: {id : menuId},
  dataType: "html"
});

request.done(function(msg) {
  $("#log").html( msg );
});

request.fail(function(jqXHR, textStatus) {
  alert( "Request failed: " + textStatus );
});

这篇关于阿贾克斯教程后,获得的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆