2013-04-09 45 views
0

下面的代碼工作正常,但我用demo.php解決了跨域問題,我怎樣才能做到這一點與出使用PHP,BCS客戶端不想PHP如何解決跨域問題與出使用php

$('#basic-search').submit(function(el){ 


     var searchdata=$('#search-text').val(); 

      $.ajax({ 
        type:"POST" , 
       url:'demo.php', 
       data:{ 
       address: 'http://search-harbinger-n5nyhive6kr72z37m6qrz2xxie.us-east-1.cloudsearch.amazonaws.com/2011-02-01/search?q='+searchdata+'*&results-type=json&return-fields=message&size=10', 
       }, 
       success:function(response){ 
       if(response!=""){ 
       response = jQuery.parseJSON(response); 
       $.each(response.hits,function(indx,obj){ 
        if($.isArray(obj)) { 
         $('.search-results').empty();  
         $('.search-results').prepend('<div class="basic-results">Results ('+ obj.length+')</div>'); 
         if(obj.length!="0"){ 
         for(var i=0;i<obj.length;i++){ 
          var $temp = '<div class="serach-results-items"><div class=""><b>ID : '+obj[i].id +'</b></div><div class="search-cont"> <b>Message :</b> '+obj[i].data.message+'</div></div>'; 
          $('.search-results').append($temp); 
          $('.submit-btn').css('display','none'); 
         } 
         } 

         else{ 
         $('.search-results').append('<div><div>Your search-<b>'+searchdata+'</b>-did not match any documents.</div><div>Make sure that all words are spelled correctly.</div></div>'); 
         $('.submit-btn').css('display','none'); 
         } 
        } 
       }); 

       } 
       else{alert('something went wrong.');} 
      } 
      }); 

     }); 

回答

0

您應該使用JSONP跨域調用,這樣

$.ajax({ 
      type:"POST" , 
      url:'demo.php', 
      data:{ 
      address: 'http://search-harbinger-n5nyhive6kr72z37m6qrz2xxie.us-east-1.cloudsearch.amazonaws.com/2011-02-01/search?q='+searchdata+'*&results-type=json&return-fields=message&size=10', 
      } 
     dataType: 'jsonp', 
     jsonp: 'callback', 
+1

這樣我就可以刪除demo.php正確的,我可以添加URL直接右 – Prashobh 2013-04-09 09:06:10

+0

是刪除URL和嘗試。 – 2013-04-09 09:34:05