0

Hello friends please help me for following question

  1. How to pass data in JSON and how to get JSON data in php using following code

    eg: $.getJSON("url",function(data) { alert(data); });

php file:::::

<?php    how to get JSON data here?     ?>
0

1 Answer 1

1

The below is a sample server side code i.e. php code (you asked for php)

This includes fetching data from sql and encoding it into JSON format and returning it to client.

File content of testAJAX_getJson.php

 $con =
 mysql_connect("localhost","peter","abc123");
 if (!$con)   {   die('Could not
 connect: ' . mysql_error());   }

 mysql_select_db("my_db", $con);

 $result = mysql_query("SELECT * FROM
 Persons");

 while($row =
 mysql_fetch_array($result))   {  
 $data[] = $row;   }

 echo json_encode($data); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.