I have this post request code in jquery, which seems to send the request and get back results (I can see it in fiddler) but somehow in the webapp it is going to error and giving a empty alert. whats wrong?
var jqxhr =$.post("http://abhishek:9090/abc/login.action",
{ emailaddress: e_add,
projectid: p_id },
function(xml)
{
/*not coming here, goes to error*/
if($(xml).find('isSuccess').text()=="true")
{
sessiontoken=$(xml).find('sessiontoken').text();
var formMainRef=document.createElement("form");
formMainRef.action="http://abhishek:9090/abc/home.action";
formMainRef.method="post";
formMainRef.target="_self";
formMainRef.id="launch";
document.body.appendChild(formMainRef);
var cfgemailField = document.createElement("input");
cfgemailField.name="emailaddress";
cfgemailField.type="hidden";
cfgemailField.value=e_add;
formMainRef.appendChild(cfgemailField);
var cfgpidField = document.createElement("input");
cfgpidField.name="projectid";
cfgpidField.type="hidden";
cfgpidField.value=p_id;
formMainRef.appendChild(cfgpidField);
var cfgstField = document.createElement("input");
cfgstField.name="sessiontoken";
cfgstField.type="hidden";
cfgstField.value=sessiontoken;
formMainRef.appendChild(cfgstField);
setCookie("abcsessionid", sessiontoken , 1);
setCookie("abcusername",e_add,1);
formMainRef.submit();
}
}
)
.error(function() {
if(jqxhr.responseText == 'INVALID_SESSION') {
alert("Your Session has been timed out");
window.location.replace("/abc/view/index.html");
}else {
/*comes here, after sending request*/
alert( jqxhr.responseText);
}
});
login.action returns a small xml
<Response>
<sessiontoken>4611686352224309486</sessiontoken>
<isSuccess>true</isSuccess>
</Response>
Including the domain is an issue due to the potential of cross domain requests that the browser would block. By using relative paths, you are double confirming that the script you’re posting to, resides on your local server, bypassing any potential security restrictions