Advertisement
Guest User

Atualizando dados com Ajax/jQuery

a guest
Oct 26th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. :::: FIZ EXEMPLO COM UM CAMPO NA AÇÃO "CHANGE" ::::
  2. :::: VOCÊ PODE FAZER NA AÇÃO "SUBMIT" ::::
  3.  
  4. VIEW
  5. ----
  6. <div class="row">
  7. <div class="col-md-12">
  8. <label>Nome do favorecido:</label>
  9. <input type="text" name="nome" id="up_nome" value="<?php echo $nome['nome'] ?>" class="form-control input-lg" />
  10. </div>
  11. </div>
  12.  
  13. CONTROLLER
  14. ----------
  15. public function upnome()
  16. {
  17. $nome = $this->input->post("nome");
  18. $load = $this->blogs_model->upnome(1, $nome);
  19.  
  20. echo json_encode($load);
  21. }
  22.  
  23. MODEL
  24. -----
  25. public function upnome($id, $nome)
  26. {
  27. $this->db->where("id", $id);
  28. return $this->db->update("users", array("nome" => $nome));
  29. }
  30.  
  31. AJAX
  32. ----
  33. $("#up_nome").on("change", function(){
  34.  
  35. var nome = $("#up_nome").val();
  36.  
  37. console.log(nome);
  38. /* ------------------------- */
  39.  
  40. $.ajax({
  41. url: CAMINHO_JAVASCRIPTI+'/blogs/upnome',
  42. type: 'POST',
  43. data: {nome: nome},
  44. dataType: 'json',
  45. success: function(data){
  46.  
  47. alert("Modificado");
  48. }
  49.  
  50. });
  51.  
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement