I wrote XMLhttpRequest function for making a ajax POST.When I add new job this function is called and added job is also shown in HTML.The code is below.
function req_add()
{
var hr = new XMLHttpRequest();
var url = "To-Do.php";
var content = document.getElementById("content").value;
var vars = "content=" + content;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type","application/x-www-form-
urlencoded");
hr.onreadystatechange=function()
{
if(hr.readyState == 4 && hr.status == 200)
{
var return_data = hr.responseText;
document.getElementById("result").innerHTML
= return_data;
}
}
hr.send(vars);
document.getElementById("result").innerHTML =
"Processing...";
}
In advance I was using $.getJSON for GET operation.Now I want to write a function that both GET and POST requests can be done.The function will be like this=> makeRequest(type,params,URL) ,type is for POST and GET. There will be onsuccess function whether the data is returned successfully or not.And when I write common function will I use hr.send ()? Thanks.