2014-09-01 62 views
0

我试图通过表单发送表单。 Ajax,但无法弄清楚如何将接收器设置为一个php脚本。当试图传递数据时,我找不到404页面。我不知道如何定义.php脚本我希望数据被发送,并希望有人能够提供帮助。Drupal如何为AJAX表单定义页面POST

我试图在页面

<?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> 

开始定义脚本路径我仍然得到错误 可能找不到你请求的网站“/ no de/modules/test/customer.php“ 如何摆脱节点部分并获取脚本将数据发送到正确的地址? 任何帮助将不胜感激。

回答

0

删除下面的代码,表单页面回调函数

module_load_include('php', 'mysite', 'modules/test/customer'); 

,并把它添加到hook_init

它会解决你的问题。