I'm totally new to jQuery and I need to rewrite this bit of javascript to jQuery. Can you help me out? Is this correct?
Javascript:
var xmlHttpRequest = new XMLHttpRequest();
function getTasks(){
var name=document.getElementById("name").value;
var summary=document.getElementById("summary").value;
if (xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200)
{
document.getElementById("open").innerHTML=xmlHttpRequest.responseText;
}
xmlHttpRequest.open("Post","jsontaskmanager?name=" + name + "&summary=" + summary, true);
xmlHttpRequest.send();
}
jQuery:
var xmlhttp = new XMLHttpRequest();
$("document").ready(function(){
var name = $("name").val();
var summary = $("summary").val();
//blah
$.ajax({
url: "jsontaskmanager",
type: "POST",
dataType: "json",
data: { name: name, summary: summary },
success: function(response) {
$("open").html(response);
}
});
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…