2016-11-01 2 views
0

Prestashop 1.6에서 AJAX 호출을 작성하고 모든 Ajax 관련 코드를 보유 할 ajax.php 파일을 호출하려고합니다. 은 $ 아약스를 보유하고 내 jQuery를 기능 ({})데이터가 AJAX 호출에서 수신되지 않습니다.

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"); 
       } 
      }) 
      } 
     }; 

그리고 내가 가진 한 ajax.php 파일에 있습니다

<?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(); 
} 

?> 

내가 될 것입니다 여기에 잘못된 무엇입니까 어떤 생각 높게 평가!

+0

나는 보통 '데이터'를 보내지 않지만 두 번째 매개 변수로 전송하려면 'method_id ='앞에 '&'가 필요하다고 생각합니다. 응답을 전송하지 않거나 전송하지 않습니까? 나는'ajax_function'이'set_customerrier_method'와 같다고 생각하지 않습니다. – chris85

+2

'{ajax_function : 'set_customcarrier_method', method_id : method_id} ' – Qsprec

+0

과 같은 데이터를 보내기 위해 객체를 사용하는 것이 더 좋습니다. j 쿼리 라이브러리가 사용 되나요? – Balan

답변

0

당신은 &

변수 둘 사이
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"); 
       } 
      }); 
      } 
     } 
관련 문제