我在我的服務器上創建了一個ajax.php文件,並使用jquery使用ajax將id發送到該文件。laravel在laravel中發送ajax後在自定義文件中查詢?
我想在該ajax.php文件中運行db查詢來獲得結果。
我無法做到這一點。
你能幫我嗎。
jQuery代碼:
$('.invitebyemail').click(function(){
var email = $('#add-members-event-email').val();
var eventid = $('.eventid').val();
var pathname = window.location.pathname; // Returns path only
var url = window.location.href; // Returns full URL
var APP_URL = {!! json_encode(url('/')) !!};
alert(APP_URL);
alert(url);
$.ajax({
url: APP_URL+'/ajax.php',
type: 'POST',
data: { id: eventid },
success: function (data) {
alert(data);
},
error: function() {
alert('error');
}
});
return false;
});
阿賈克斯文件代碼:
use DB;
$eventid = $_POST['id'];
echo $eventid;
$users = DB::table('users')->get();
print_r($users);
感謝
什麼是您保存ajax.php的路徑? –
該文件在公共文件夾中。@SérgioReis,ajax文件工作正常,但我試圖在其中使用sql查詢。 –