Jump to content

How to add a ajax-tab request in 1.5 module [resolu]


erotikat

Recommended Posts

Hi,

 

I create a mvc module, without tpl, and i want to request customers table with ajax.

public function ajaxProcess()
{
 if (Tools::isSubmit('customerFilter'))
 {
  $search_query = trim(Tools::getValue('q'));
  $customers = Db::getInstance()->executeS('
  SELECT `id_customer`, `email`, CONCAT(`firstname`, \' \', `lastname`) as cname
  FROM `'._DB_PREFIX_.'customer`
  WHERE `deleted` = 0 AND is_guest = 0 AND active = 1
  AND (
	`id_customer` = '.(int)$search_query.'
	OR `email` LIKE "%'.pSQL($search_query).'%"
	OR `firstname` LIKE "%'.pSQL($search_query).'%"
	OR `lastname` LIKE "%'.pSQL($search_query).'%"
  )
  ORDER BY `firstname`, `lastname` ASC
  LIMIT 50');
  die(Tools::jsonEncode($customers));
 }
}

 

But when i request it from a js

function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
 return "";
  else
 return results[1];
}
var currentToken = gup( 'token' );
$('#customerFilter')
.autocomplete(
  'ajax-tab.php', {
  minChars: 2,
  max: 50,
  width: 500,
  selectFirst: false,
  scroll: false,
  dataType: 'json',
  formatItem: function(data, i, max, value, term) {
	return value;
  },
  parse: function(data) {
	var mytab = new Array();
	for (var i = 0; i < data.length; i++)
	 mytab[mytab.length] = { data: data[i], value: data[i].cname + ' (' + data[i].email + ')' };
	return mytab;
  },
  extraParams: {
	controller: 'AdminMyModule',
	token: currentToken,
	customerFilter: 1
  }
 }
)
.result(function(event, data, formatted) {
 $('#id_customer').val(data.id_customer);
 $('#customerFilter').val(data.cname + ' (' + data.email + ')');
});

 

 

i receive a blank answer.

 

So how can i report the AdminCartRulescontroller ajax-tab in a mvc module without tpl ?

 

Thanks for yours helpfull.

 

Voir module Adminloyalty

Edited by erotikat (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...