2013-03-11 23 views
4

我正在使用SOAP Web服務從其他服務器獲取響應。我正在使用jquery ajax調用來從服務器獲取數據。但是我從服務器獲取(零)狀態代碼。如何使用JQuery使SOAP請求跨域

如何使用Jquery實現跨域的ajax調用?

+1

之前問這個問題,顯示你的代碼,你已經在這個問題上所做的努力。 在服務器允許的情況下,您無法進行跨域請求。 CORS的支持基本上由HTTP中的「Access-Control-Allow-Origin」頭部檢查。 http://enable-cors.org/。如果服務器支持CORS,則提供回調。 – 2013-03-11 06:26:49

+0

有一個jquery插件,它使用YQL API做跨域請求:https://github.com/padolsey/jQuery-Plugins/tree/master/cross-domain-ajax/ – 2013-03-11 06:54:55

+0

可能的重複[是否有可能使用jquery獲取跨域SOAP請求](http://stackoverflow.com/questions/12090036/is-it-possible-to-get-cross-domain-soap-request-using-jquery) – nneonneo 2013-03-12 03:16:16

回答

1

而不是嘗試使用jQuery獲取跨域數據,請嘗試使用PHP或允許跨域訪問的其他語言獲取數據。創建一個加載SOAP數據的PHP頁面,並使用jQuery將該信息嵌入到頁面中。雖然它不是一個SOAP連接,來說明這個想法,你可以創建這個PHP頁面加載YouTube視頻:

<?php 
$vid = filter_var($_POST['id'], FILTER_SANITIZE_STRING); 
?> 
<?php if ($vid) : ?> 
    <iframe title="YouTube video player" width="510" height="317" src="http://www.youtube.com/embed/<?php echo $vid; ?>?autoplay=1" frameborder="0" allowfullscreen></iframe> 
<?php endif; ?> 

然後使用jQuery來顯示它 - 點擊一個鏈接可以調用這個函數:

function loadContent() { 
$(this).parent().load("/youtube-video.php",{id:video_id},showNewContent()); 
} 
0

你的問題似乎很模糊。但下面是做跨域請求jQuery中的方法之一:

$(function() { 
      $.ajax({ 
       type:'GET', 
       dataType:'jsonp', 
       jsonp:'jsonp', 
       url:'http://api.stackoverflow.com/1.0/tags/', 
       success:function(data) { 
        $.each(data["tags"], function(index, item) { 
         var $tag = item.name; 
         var $count = item.count; 
         $("body").append('<div class="stackoverflow"> The Tag 
       <span class="q-tag">' + $tag + '</span> has < 
span class="q-count">' 
+ $count + '</span> Questions.</div>') 
        }); 
       }, 
       error:function() { 
        alert("Sorry, I can't get the feed"); 
       } 
      }); 
     }); 

DEMO

DESCRIPTION OF THE ABOVE