[英]Drupal how to define page for AJAX form POST
我正在嘗試通過Ajax發送表單,但無法弄清楚如何將接收者設置為PHP腳本。 嘗試傳遞您的數據時,找不到404頁。 我不知道如何在PHP腳本中定義要將數據發送到的位置。
我嘗試在頁面開頭定義腳本路徑
<?php
module_load_include('php', 'mysite', 'modules/test/customer');
?>
AJAX部分
$(document).ready(function() {
// process the form
$('form').submit(function(event) {
// get the form data
// there are many ways to get this data using jQuery (you can use the class or id also)
var formData = {
'id' : $('input[name=mav_id]').val(),
'sku' : $('input[name=sku1]').val(),
};
// process the form
$.ajax({
type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
//redining the base path
url: Drupal.settings.basePath + "modules/test/customer" ,
data : formData, // our data object
dataType : 'json', // what type of data do we expect back from the server
encode : true
})
// using the done promise callback
.done(function(data) {
// log data to the console so we can see
console.log(data);
// here we will handle errors and validation messages
});
// stop the form from submitting the normal way and refreshing the page
event.preventDefault();
});
});
HTML表格
<table>
<tr><th align="LEFT"><b><i>Cu data</b></i></th></tr>
<form action="modules/test/customer.php" method="post">
<div class='cu'>
<tr><td>Mav ID: <input type="text" name="mav_id"></td>
<td>sku: <input type="text" name="sku1"></td>
<tr> <td><input type="submit" value="Submit"></td> </tr>
我仍然收到此錯誤:
找不到您要求的網站“ /node/modules/test/customer.php
如何擺脫節點部分並獲取腳本以將數據發送到正確的地址?
刪除以下代碼形式的頁面回調函數
module_load_include('php', 'mysite', 'modules/test/customer');
並將其添加到hook_init
它會解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.