Aide pour envoie de données vers un fichier php depuis javascrip

Fermé
forgottenspam Messages postés 26 Date d'inscription mardi 14 octobre 2014 Statut Membre Dernière intervention 10 décembre 2014 - 3 déc. 2014 à 11:25
forgottenspam Messages postés 26 Date d'inscription mardi 14 octobre 2014 Statut Membre Dernière intervention 10 décembre 2014 - 4 déc. 2014 à 11:46
Bonjour,

alors je vous pose mon problème j'ai récupérer des données via ajax et je souhaite les envoyer sur un fichier php pour les ajouter dans ma base de données

voici le code javascript :

$(document).ready(function() {

/*Radius Search Using Your Own Custom Data Table*/
$.ajax({
url: 'http://www.mapquestapi.com/search/v2/radius',
dataType: 'jsonp',
crossDomain: true,
data: {
key: decodeURIComponent(key),
origin: '36.793626,10.277790', /*origin of the radius search*/
radius: 1, /*radius of search in kilometre*/
hostedData: 'mqap.145112_hanglocationstest|' /*the hosted data table you want to search along with query to narrow the results*/
},
success: function(data, textStatus, jqXHR) {
var pois = new MQA.ShapeCollection();
var html = '<table width="200px" align="center">'; /* 200<thead><tr><th>Announcer_ID</th><th>Name</th><th>ADDRESS</th><th>Discription</th><th>DISTANCE (k)</th></tr>*/

/*Add POI markers and populate the search result table*/
for (i=1;i<data.searchResults.length;i++) {
var location = new MQA.Poi({lat:data.searchResults[i].shapePoints[0],lng:data.searchResults[i].shapePoints[1]});

/*Change default POI icons to numbered icons*/
var numberedPoi = new MQA.Icon('http://www.mapquestapi.com/staticmap/geticon?uri=poi-' + (i+1) + '.png',20,29);
location.setIcon(numberedPoi);

/*Populate the content within the InfoWindows*/
location.setRolloverContent('<div style="width:200px; font:bold 14px Helvetica, Arial, sans-serif;">' + data.searchResults[i].fields.title_annonce + '</div>');
location.setInfoContentHTML('<div style="width:200px; font:bold 14px Helvetica, Arial, sans-serif;">' + data.searchResults[i].fields.title_annonce + '</div>' + data.searchResults[i].fields.title_place + '<br />' + data.searchResults[i].fields.desc_id + ', CO ');

pois.add(location);
/*<td>' + data.searchResults[i].resultNumber + '</td>*/

html += '<tr><td align="center">' + data.searchResults[i].fields.title_annonce + '</td></tr><tr><td align="center">' + data.searchResults[i].fields.desc_id + '</td></tr><tr><td align="center">' + data.searchResults[i].fields.title_place + '</td></tr><tr><td align="center"><b>A </b>'+ data.searchResults[i].distance + '<b> K</b></td></tr>';
}

html += '</table>';

document.getElementById('searchResults').innerHTML = html;

pour le moment j'affiche les données récupérer via ajax sur un tableau mais je voudrais enlever le tableau et envoyer tous dans un fichier php puis je vais crée une requête pour les ajouter dans ma base de données merci d'avance

A voir également:

3 réponses

jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
3 déc. 2014 à 11:39
Bonjour,

A la limite.. il suffit que tu fasse de L' AJAX dans ton AJAX ...

 /*Radius Search Using Your Own Custom Data Table*/
        $.ajax({
          url: 'http://www.mapquestapi.com/search/v2/radius',
          dataType: 'jsonp',
          crossDomain: true,
          data: {
            key: decodeURIComponent(key),
            origin: '36.793626,10.277790',                  /*origin of the radius search*/
            radius: 1,                             /*radius of search in kilometre*/
            hostedData: 'mqap.145112_hanglocationstest|'         /*the hosted data table you want to search along with query to narrow the results*/
          },
          success: function(data, textStatus, jqXHR) {

             $.ajax({
                url: 'Ton_Fichier.php',
                 dataType: 'jsonp',
                 data: { valeur1 = data.tttt, valeur2=data.tititi  ..etc...},
                 success: function(data, textStatus, jqXHR) {
                 
                 }
          // ...

     }
   });


 // etc...

0
forgottenspam Messages postés 26 Date d'inscription mardi 14 octobre 2014 Statut Membre Dernière intervention 10 décembre 2014 1
3 déc. 2014 à 14:47
Merci d'ailleurs en attendant une réponse j'ai commencer a intégrer de l'ajax dans ajax.
je vous tiens au courant si ça marche ou non
0
forgottenspam Messages postés 26 Date d'inscription mardi 14 octobre 2014 Statut Membre Dernière intervention 10 décembre 2014 1
Modifié par forgottenspam le 4/12/2014 à 11:48
comment je peut récupérer ces données en php
js:
var datastring ='stfield'+data.searchResults[i].fields.title_annonce+'&ndfield'+data.searchResults[i].fields.desc_id+'&rdfield'+data.searchResults[i].fields.title_place+'&thfield'+data.searchResults[i].distance;
   $.ajax({
                url: '..Connections/annonces.php',
                 dataType: 'jsonp',
                 data: datstring,
                 success: function(data, textStatus, jqXHR) {
                 debugger;
                 }
   });



j'ai essayer ça
php :
<?php

include_once('hangingdb.php');

 
$str = file_get_contents('datastring');
$json = json_decode($str, true); // decode the JSON into an associative array
$stfield = $json ['data'];
echo $stfield

?>


mais ça marche pas :'(
0