2012-05-05 37 views
0

我在jquery中有這個帖子請求代碼,它似乎發送請求並返回結果(我可以在提琴手中看到它),但以某種方式在web應用程序中,它將發生錯誤並給出空警報。怎麼了?我的帖子請求有什麼問題?

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> 
+0

嘗試刪除域名並僅使用相對路徑(如$ .post(「/ abc/login.action「,... – Bryan

+0

@BryanMoyles:它在那種情況下工作..包括域在這裏應該是一個問題? – abi1964

回答

0

包括域名是一個問題,因爲該瀏覽器會阻止跨域請求的潛力。通過使用相對路徑,您可以雙倍確認您發佈的腳本駐留在本地服務器上,繞過任何潛在的安全限制

+0

情景是我有一箇舊的webapp託管在'http:// ab:11111/abc' (這是很久以前在c + +),並且這個請求是從這個頁面本身發出,一些檢查完成,如果它滿足條件去更新版本的webapp(用完全不同的語言Java),它應該去' http:// de:22222/def' webapp。是這樣的可能嗎? – abi1964

+0

我的建議是發佈到本地腳本,然後向適當的服務器發送後端curl請求,並返回適當的內容。通過使用服務器端腳本作爲您的代理,您將繞過任何瀏覽器安全限制 – Bryan

相關問題