Ajax Function Live Preview From Drop Down List
I'm having a little trouble configuring a live preview of data via AJAX. I managed to get a preview with the following code but I'm a bit stuck in how to proceed. My next step is d
Solution 1:
In your case the PHP file should return json object that you can use in ajax success callback. Please refer Returning JSON from a PHP Script from returning json from server. in case of object sample code goes like,
$res = newstdClass();
$res->name = "sample"; // from db$res->imageUrl = "img/img1.png";// from dbecho json_encode($res);
In your js file you can do something like,
$.ajax({
type:"POST",
data:{opts: opts},
url:"views/itemOverview.php",
datatype: "text/json", // this is preferred when receiving json datasuccess:function(res){
// res is json object. res.name & res.imageUrl are it's property
$("#results").html("<p>Uw items : " + res.name + " <img src='"+ res.imageUrl+"' /></p>");
}
})
Post a Comment for "Ajax Function Live Preview From Drop Down List"