Load mysqli php data via ajax call -


what i'm trying calling database data via ajax , php. ajax call doesn't work, , can't find out solution on web.

so here code:

test.php

<?php  include_once 'db_class.php';  $cat = $_get['cat'];    $dbconn = new dbconn('localhost', 'root', 'somepsw', 'blog');   $dbconn->set_query("select * posts category = '".$cat."'");   echo '<br/>'.$dbconn->query.'<br/>';   $result = $dbconn->result;   $num = $dbconn->num_results;   $array = mysqli_fetch_assoc($result);   echo json_encode($array); ?> 

if type url on browser: http://127.0.0.1:82/blog/ws/test.php?cat=css

the data returned via jsonencode correct, when i'm loading on html page jquery can't read data.

test.html

<html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script> function ajaxcall() {  var css;  $.ajax({                                             url: 'test.php',       type: "get",            data: {cat: css},                     datatype: 'json',           success: function(rows)                {       alert(rows);        },       error: function() { alert("an error occurred."); }      });      }      ajaxcall();  </script> </head> <body></body> </html> 

thanks in advance.

your variable css has no value. wanted use string 'css'. maybe want able load other categories, too. change ajaxcall function to

function ajaxcall(category) {     $.ajax({         url: 'test.php',         type: "get",         data: {cat: category},         datatype: 'json',             success: function(rows) {            alert(rows);         },         error: function() {            alert("an error occurred.");         }     }); } 

and call using

ajaxcall('css'); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -