0

我在 jquery 中有这个发布请求代码,它似乎发送请求并返回结果(我可以在 fiddler 中看到它)但不知何故在 webapp 中它会出错并给出一个空警报。怎么了?

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 返回一个小 xml

<Response>
  <sessiontoken>4611686352224309486</sessiontoken>
  <isSuccess>true</isSuccess>
</Response>
4

1 回答 1

0

由于浏览器可能会阻止跨域请求,因此包含域是一个问题。通过使用相对路径,您可以双重确认您发布到的脚本位于您的本地服务器上,从而绕过任何潜在的安全限制

于 2012-05-05T07:24:44.450 回答