我使用struts2
和jquery
我正在使用XMLHttpRequest
的正常工作的服務器的請求,我希望有一個等價的jQuery解決方案等效jQuery的服務器調用我的XMLHttpRequest不工作
function submitLogin()
{
if(validate()) //this is true
{
var url_action="/csm/login.action";
var client;
var dataString;
if (window.XMLHttpRequest){
client=new XMLHttpRequest();
} else {
client=new ActiveXObject("Microsoft.XMLHTTP");
}
client.onreadystatechange=function(){
if(client.readyState==4&&client.status==200)
{
}
};
dataString="emailaddress="+document.getElementById("email_id").value+"&projectid="+document.getElementById("project_id").value;
client.open("POST",url_action,true);
client.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
client.send(dataString);
}
}
上述作品完美,所以在jQuery中我寫了下面的代碼,但它不工作,可能是什麼問題?
function submitLogin()
{
if(validate()) //this is true
{
$.post("/csm/login.action",function(xml) {
alert(xml);
});
}
}
您是否使用req發送數據? – Rafay
3nigma:雅我完全錯過了。我發送'dataString =「emailaddress =」+ document.getElementById(「email_id」)。value +「&projectid =」+ document.getElementById(「project_id」).value;'數據 – abi1964
感謝所有,但3nigma:發現問題第1 – abi1964