简体   繁体   中英

Tutorial for ajax form posting

I am looking for a short and easy tutorial for posting form data using ajax & POST. More specifically for comments in a custom wordpress theme.

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). I've also searched on this site but most threads use jQuery or do not cover what I'm looking for.

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 :).

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

Cheers, S.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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