简体   繁体   English

Ajax表单发布教程

[英]Tutorial for ajax form posting

I am looking for a short and easy tutorial for posting form data using ajax & POST. 我正在寻找一个简短易用的教程,以使用Ajax和POST发布表单数据。 More specifically for comments in a custom wordpress theme. 更具体地说,用于自定义wordpress主题中的评论。

So far I have only found this: http://www.simonerodriguez.com/ajax-form-submit-example/ but the js file is huge so I think there is a lot of bloat (couldn't decipher it all). 到目前为止,我只发现了这一点: http : //www.simonerodriguez.com/ajax-form-submit-example/但js文件很大,所以我认为有很多膨胀(无法完全解密)。 I've also searched on this site but most threads use jQuery or do not cover what I'm looking for. 我也在此站点上进行了搜索,但是大多数线程使用jQuery或没有涵盖我所寻找的内容。

Do any of you know a tutorial for this, or could anyone explain the basic code to me? 你们当中有人知道这个教程吗,或者有人可以向我解释基本代码吗?

Thanks a lot for your help and suggestions! 非常感谢您的帮助和建议!

PS please do not suggest jQuery as I am not using it and want to learn pure Js :). PS请不要建议jQuery,因为我没有使用它,而是想学习纯Js :)。

function initiateRequest() 
{
  if(window.XMLHttpRequest) {
        return new XMLHttpRequest();
  } else {
        return new ActiveXObject("Microsoft.XMLHTTP");
  }
}



function createClearingHouse() {

    parameters = "name=" + document.getElementById("username").value;
    url = EnginePath + "/clearingHouse/persist"
    request = initiateRequest();
    request.open("POST", url, false);
    request.send(parameters);
    if(request.readyState==4  && (request.status == 200)) {         
       alert("success");
    }
}

As I've been asked for it... Here is a quite complete link: 正如我所要求的那样...这是一个非常完整的链接:

http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml

Cheers, S. 干杯,S。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM