jquery - An Example for using AJAX calls to the controller method using JSON data -


i trying learn ajax,json,jquery using in asp.net mvc.i want simple example ajax call made controller.the controller has json data.an example

first name :  age :  submit

it takes name,age , submit button can implement ajax.how do using json data.it great if can explain me example have provided above.

this how ajax call should :

$.ajax({  url:  data:  datatype:  });

php exemple :

 <?php  if(isset($_post)){       $f_panne=$_post['f_panne'];      $p=$_post['produit'];     $bdd = new pdo('mysql:host=localhost;dbname=reparation', 'root', '');        $req2 = $bdd->prepare('select  count(*) nbre  modele_produit join panne_produit on  modele_produit.id_modele=panne_produit.id_produit          join type_panne on panne_produit.id_panne=type_panne.code_type_panne        join famille_panne on type_panne.code_panne=famille_panne.code_panne famille_panne.nom_panne=? , modele_produit.nom_modele= ?');         $req2->execute(array($f_panne,$p));        $response["nombre_panne"] = array();       while(  $donnees2 = $req2->fetch()){       $type = array();         $type ['nbre']=$donnees2['nbre'];         array_push($response["nombre_panne"], $type);     }       print  json_encode($response); }  ?> 

in jquery :

  $.ajax({    type:"post",    url:"traitement/panne/calculer_nombre_famille_panne.php",    data:{f_panne:f_panne,produit:produit},    success:function(data){    var obj = jquery.parsejson(data);    jquery.each(obj["nombre_panne"], function(index, value) {     // console.log(value.nbre);    })   } }); 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -