2014-09-01 2 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 FORM

<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

это решит вашу проблему.

Смежные вопросы