Wednesday, September 15, 2010

return multiple json value in php json and javascript

How to post data and return multiple value as JSON data type in php


1) pro_process.php

<?php
$colName=$_POST['colName'];
$productData="p1";
$anchors="a1";
$arr=array(productData=>"$productData", anchor=>"$anchors");
$json=json_encode($array);
echo $json;
?>


2) pro_process.html

$.post('pro_process.php',
{'colName':colName},
            function(result) {
                var obj=(jQuery.parseJSON(result));
                alert(obj.productData);
                alert(obj.anchor);
           
            }
        );

No comments:

Post a Comment