用于发布和获取的 Ajax 教程 [英] Ajax tutorial for post and get

查看:26
本文介绍了用于发布和获取的 Ajax 教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个简单的输入表单的简单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);
  }
});

这段代码会将test.html文件的内容附加到#results元素

This code will append the content of test.html file to #results element

您可以在 jQuery 网站上找到更多信息.

You can find more information at jQuery website.

更新:

使用此代码发送POST数据并输出结果.

Use this code 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 );
});

这篇关于用于发布和获取的 Ajax 教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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