Jump to content

Ecrire du sql en javascript, avec ajax ?


Recommended Posts

Bonjour,

 

Dans la fonction de l'action au clic sur le marqueur, il faudrait rajouter une fonction $.ajax (regardez sur ajax-cart.php pour avoir des exemple, sinon dans mon exemple 1) qui ferait une requete pour poster des variables JS vers un fichier php que vous allez créerez pour faire la requete PHP (voir exemple2).

 

Exemple 1 : requete AJAX dans un fichier JS

$.ajax({
	type: 'POST',
	headers: { "cache-control": "no-cache" },
	url: baseDir + 'modules/blockcart/blockcart-set-collapse.php' + '?rand=' + new Date().getTime(),
	async: true,
	cache: false,
	data: 'ajax_blockcart_display=expand'
});

Exemple 2 : récupération des variables sur un fichier php

include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/../../init.php');
if ( isset($_POST['ajax_blockcart_display']) || isset($_GET['ajax_blockcart_display']))
{
   $ajax_blockcart_display=$_GET['ajax_blockcart_display'];
   // echo $ajax_blockcart_display;
   /* requete SQL à faire ici */ 
}

Bon courage
  

Link to comment
Share on other sites

  • 5 weeks later...

Salut, et merci. J'ai pas eu d'alert me disant que quelqu'un avait répondu, désolé...j'avais oublié ce post, car trouvé une méthode un peu dans le même style, je passe par un formulaire pour stocker les infos, puis j'utilise ajax pour l'envoyer et je récupère donc en php les infos.

Link to comment
Share on other sites

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