我正在尝试通过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>
我仍然收到此错误:
无法找到您要求的网站&#34; /node/modules/test/customer.php
如何摆脱节点部分并让脚本将数据发送到正确的地址?
答案 0 :(得分:0)
删除以下代码表单页面回调函数
module_load_include('php', 'mysite', 'modules/test/customer');
并将其添加到hook_init
它将解决您的问题。