2016-11-01 5 views
0

Prestashop 1.6でAJAX呼び出しを作成しようとしていて、すべてのAjax関連のコードを保持するajax.phpファイルを呼び出しています。AJAXコールでデータが受信されない

<?php 
session_start(); 
/* SSL Management */ 
$useSSL = true; 

require_once(dirname(__FILE__).'../../../config/config.inc.php'); 
require_once(dirname(__FILE__).'../../../config/smarty.config.inc.php'); 
require_once(dirname(__FILE__).'../../../init.php'); 
include_once(dirname(__FILE__).'/customcarrier.php'); 

$customcarrier = new CustomCarrier(); 

if (Tools::getValue('ajax_function') == 'set_customcarrier_method') { 
    $customcarrier->setCustomCarrierMethod(); 
} 

?> 

私がここで間違って何を取得していますすべてのアイデアは次のようになります({})$のアヤックスを保持している私のjQueryの関数は

私が持っているajax.phpファイルに続いて
function setCustomCarrierMethod(method_id){ 
      if (method_id) { 
      $.ajax({ 
       url: baseDir + '/modules/customcarrier/ajax.php', 
        type: 'POST', 
        data: 'ajax_function=set_customcarrier_method' + 'method_id=' + method_id, 
        dataType: 'json', 
       success: function(json) { 
       console.log("successfull request"); 
       }, 
       error: function(json) { 
       alert(json.error); 
       console.log("error in the request"); 
       } 
      }) 
      } 
     }; 

です高く評価!

+0

私は通常、そのような 'data'を送信しませんが、' method_id = 'の前に'& 'が必要で2番目のパラメータとして送信されると思います。送信していない、または応答を返さないのですか?私は 'ajax_function'は' set_customerrier_method'と同じではないと思います。 – chris85

+2

'{ajax_function: 'set_customerrier_method'、method_id:method_id}' – Qsprec

+0

はクエリライブラリを参照しましたか? – Balan

答えて

0

あなたは& 2の間の変数

data: 'ajax_function=set_customcarrier_method' & 'method_id=' + method_id 

を使用する必要があります。

function setCustomCarrierMethod(method_id){ 
      if (method_id) { 
      $.ajax({ 
       url: baseDir + '/modules/customcarrier/ajax.php', 
        type: 'POST', 
        data: 'ajax_function=set_customcarrier_method' & 'method_id=' + method_id, 
        dataType: 'json', 
       success: function(json) { 
       console.log("successfull request"); 
       }, 
       error: function(json) { 
       alert(json.error); 
       console.log("error in the request"); 
       } 
      }); 
      } 
     } 
関連する問題