brrocks28
6/6/2016 - 10:51 AM

$.ajax post data from js to php

$.ajax post data from js to php



(function ($) {
    Drupal.behaviors.shipment_history = {
        attach: function (context, settings) {
            $.noConflict();
            $(".reshipment-button").click(function () {
                var items = new Array();
                $("input[type=checkbox]:checked").each(function () {
                    items.push($(this).attr("id"));
                });
                var base_url = window.location.origin;
                $.ajax({
                    type: "POST",
                    url: base_url + '/reshipment/getdata',
                    cache: false,
                    data: {items: items},
                    success: function (data) {
                        window.location.href = base_url + '/shipment/reshipment'; //simply redirect on click button and get data in session
                    }
                });


            });


        }
    };
})(jQuery);
//create Hook_menu

function icss_shipment_pages_menu() {
  $items = array();
  
  
  //want to post data from this page on click button
    $items['shipment-history-details'] = array(
    'title' => 'shipment history',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('shipment_history_form'),
    'file' => 'includes/shipment_history.inc',
    'file path' => drupal_get_path('module', 'icss_shipment_pages'),
    'access arguments' => array('view shipment history'),
  );
  
  
    $items['reshipment/getdata'] = array(
    'title' => 'Reshipment Get Data',
    'page callback' => 'get_reshipment_data_ajax',
   'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  ); 
    return $items;
}


function get_reshipment_data_ajax() {
  $items = "";
  if (isset($_POST['items'])) {
    $_SESSION['reshipment_data']=$_POST['items'];
  }
   return $data;
  }