2016-08-16 109 views
0

我用Request solution爲Ajax請求,但我得到一個錯誤:從HTTPS JSON發送到HTTP

reqwest.min.js:6 Mixed Content: The page at 'https://...' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://...'. This request has been blocked; the content must be served over HTTPS.

服務器端代碼(我使用WordPress插件本):

add_action('wp_ajax_nopriv_wpse144893_search', 'wpse144893_search_data'); // allow logged out users 
add_action('wp_ajax_wpse144893_search', 'wpse144893_search_data'); // allow logged in users 

function wpse144893_search_data(){ 
header('Content-type: application/json'); 
header('Access-Control-Allow-Origin: *'); 

    $errors = array(); 
    $data = array(
     'status' => 'error', 
     'message' => '', 
     'result' => array() 
    ); 

    if(!isset($_REQUEST['term']) || empty($_REQUEST['term'])) 
     $errors[] = 'No search term given!'; 


    if(!isset($_REQUEST['limit']) || empty($_REQUEST['limit'])) 
     $limit = 10; 
    else 
     $limit = (int) $_REQUEST['limit']; 

    if(empty($errors)){ 

     $term = sanitize_text_field($_REQUEST['term']); 

     // setup query data 
     $args = array(
      'posts_per_page' => $limit, 
      's' => $term 
     ); 

     $query = new WP_Query($args); // run query 

     $results = array(); 
     if($query->have_posts()): while($query->have_posts()): $query->the_post(); 
      $post_item = array(
       'title' => get_the_title(), 
       'excerpt' => get_the_excerpt(), 
       'permalink' => get_permalink() 
      ); 
      $results[] = $post_item; 
     endwhile; 
      $data['status'] = 'success'; 
      $data['message'] = 'Results found!'; 
      $data['result'] = $results; 
     else: 
      $errors[] = 'No post found!'; 
      $data['message'] = $errors; 
     endif; 
    } 

    echo json_encode($data); // print json 

    die(); // kill the script 
} 

客戶端代碼(請求插件):

reqwest({ 
    url: 'http://...' 
    , type: 'json' 
    , method: 'get' 
    , crossOrigin: true 
    , withCredentials: true 
    , error: function (err) { alert('1'); } 
    , success: function (resp) { 
    alert('2'); 
    } 
}) 

我試圖使用這個​​(在服務器代碼ABO見ve)但它不能解決問題。

+2

什麼是不清楚「的內容都必須透過HTTPS」? – Quentin

+0

因此,如果沒有將第二臺服務器轉移到https,沒有辦法使其工作。 – Alex

回答

0

問題是通過移動第二臺服務器HTTPS ......解決