2015-03-03 29 views
0

我想發送一個在jQuery中生成的數組到一個PHP文件。我被卡住了。我嘗試了幾種方法,但沒有運氣。我想在php文件中echo/print_r數組。專家給我你的好看。如何打印或獲取從jQuery發送到PHP文件的數組Wordpress

JS:我下面的代碼給出

<script> 
    jQuery(document).ready(function($){ 
     url = '<?php echo includes_url().'cs_cause.php'; ?>'; 
     var allVals = []; 
     $('#deleteProduct').click(function(){ 

      $('.delete-product:checked').each(function() { 
       allVals.push($(this).val()); 
      }); 
      $.post(url,{ array : allVals }, function(response,status){ 
        alert(response+ ' ' + status); 
      }); 
     }) 
    }) 
</script> 

PHP:

<?php 
    if($_POST['array']) 
    { 
     $r = $_POST["array"]; 
     print_r($r); 
    } 
?> 
+0

,所以我怎麼能得到陣列? – WahidSherief 2015-03-03 06:27:22

+0

最近怎麼迴應?使用'console.log(響應)' – Ghost 2015-03-03 06:29:33

+0

請看看:http://screencast.com/t/shpt3IpLOI2 @Ghost – WahidSherief 2015-03-03 06:34:00

回答

1

嘗試是這樣的隊友。

<script> 
    jQuery(document).ready(function($){ 

     url = "http://localhost/fundraise/wp-content/themes/aidreform/include/cs_cause.php"; 
     var allVals = []; 
     $('#deleteProduct').click(function(){ 

      $('.delete-product:checked').each(function() { 
       allVals.push($(this).val()); 
      }); 
      $.post(url,{ array : allVals }, function(response,status){ 
        alert(response+ ' ' + status); 
      }); 
     }) 
    }) 
</script> 

櫃面U移動這個文件到服務器URL更改爲

url = "/wp-content/themes/aidreform/include/cs_cause.php"; 
+0

你是如何知道的 - 「localhost/fundraise」?現在它顯示: http://screencast.com/t/RiDSzAXF – WahidSherief 2015-03-03 07:00:01

+0

http://stackoverflow.com/questions/13276583/fatal-error-call-to-undefined-function-add-filter-in-index-php -in-word – Outlooker 2015-03-03 07:03:31

+0

非常感謝你..我解決了它..我只是將我的PHP的東西移動到一個新的文件。現在它的工作! :) .. 非常感謝。我有好奇心的問題,你如何知道「localhost/fundraise」這個名字? 當我使用「include_url()」時出現了什麼問題? – WahidSherief 2015-03-03 07:06:59

相關問題