Saugat Thapa Saugat Thapa - 1 year ago 84
Ajax Question

how to feed value from database using ajax

$(document).ready(function() {
$(".submit").click(function(event) {
var user_name = $("input#name").val();
var password = $("input#pwd").val();
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/ajax_post_controller/user_data_submit",
dataType: 'json',
data: {
name: user_name,
pwd: password
success: function(res) {
if (res) {
// Show Entered Value

// the function of controller that the url: contains
public function user_data_submit() {
$data = array(
'username' => $this - > input - > post('name'),
'pwd' => $this - > input - > post('pwd')
echo json_encode($data);

the code is used to take value from the input field and feed it on the html based on id. but my problem is i need to feed it from select query which bring value from the database that already has the data.

Answer Source

 $(function () 
// 2) Send a http request with AJAX
  url: 'api.php',                  //the script to call to get data          
  data: "",                        //you can insert url argumnets here to pass to api.php
                                   //for example "id=5&parent=6"
  dataType: 'json',                //data format      
  success: function(data)          //on recieve of reply
    var id = data[0];              //get id
    var vname = data[1];           //get name
    // 3) Update html content
    $('#output').html("<b>id: </b>"+id+"<b> name: </b>"+vname); //Set output element html
    //recommend reading up on jquery selectors they are awesome 

THis is not the edxact answer based on my question but it exactly resembles the answer that i want which is the getting id and name from the database

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download