2011-09-01 65 views
0

我正在使用jquery ajax调用web方法。在调用Web方法如下当应用程序托管时Jquery ajax调用不工作

function test() { 
      $.ajax({ 
       type: "POST", 
       url: "DashboardAdminService.asmx/GetSecureKey", 
       dataType: "xml", 
       success: function(response) { 
       $("#KeyDetailsTable").find("tr:gt(0)").remove(); 
        $(response).find("SecureKey").each(function() { 
         if ($(this).find('Status').text() == "Active") 
          $('#KeyDetailsTable > tbody').append('<tr><td>' + $(this).find('ID').text() + '</td><td>' + $(this).find('KeyName').text() + '</td><td>' + $(this).find('Description').text() + '</td><td id=' + $(this).find('ID').text() + '><a href=' + '#' + ' onclick=\'createPopup(' + $(this).find('ID').text() + ');\'>View</a><br /><a href=' + '#' + ' onclick=\'deactivateKey(' + $(this).find('ID').text() + ');\'>Deactivate</a></td></tr>') 
         else 
          $('#KeyDetailsTable > tbody').append('<tr><td>' + $(this).find('ID').text() + '</td><td>' + $(this).find('KeyName').text() + '</td><td>' + $(this).find('Description').text() + '</td><td id=' + $(this).find('ID').text() + '><a href=' + '#' + ' onclick=\'createPopup(' + $(this).find('ID').text() + ');\'>View</a><br /><a href=' + '#' + ' onclick=\'activateKey(' + $(this).find('ID').text() + ');\'>Activate</a></td></tr>') 
        }); 

       }, 
       failure: function() { alert("failed"); } 
      }); 
     } 

也能正常工作在本地机器上,但在服务器托管当web方法调用不能正常工作,并发生内部服务器错误。

+0

你是否在虚拟目录下托管它? –

+0

@Alastair Pitts是 – user673453

+0

Javascript将不会自动调整虚拟目录...所以它正在根域下寻找..例如。 'www.me.com/DashboardAdminService.asmx/GetSecureKey',它位于'www.me.com/Virtual/DashboardAdminService.asmx/GetSecureKey'下。你需要调整你的JS以考虑到这一点。 –

回答

0

如果在不同的域中有服务URL,那么由于对“跨浏览器”兼容性的限制,Ajax方法肯定会失败。