我有一個鏈接,我想用ajax。這裏是鏈接:通過ajax傳遞GET參數
<a class="export_csv" href="ajax/createCSV.php?saleid=4"><img src="/img/record.csv.png"></a>
ajax工作正常,但我不能通過GET變量。這裏是jQuery的:
$('.export_csv').on('click', function(e){
e.preventDefault();
$.ajax({
url: 'ajax/createCVS.php',
type: 'GET',
data: $(e).data['saleid'],
success: function(results){
console.log('it worked');
}
});
});
這裏是目標PHP頁面:
<?php
include('./includes/global.php');
//$cl = new Client();
//$cl->createCSV();
echo "This Works ";
$test = $_GET['saleid'];
echo $test;
echo "did work for me";
?>
什麼是'$(E)。 data ['saleid']' –
您必須將'$(e).data ['saleid']'更改爲'{saleid:'<?= $ _ GET ['saleid'] =?>'}' – hindmost