json.php

<!DOCTYPE html Public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<script src="js/jquery-1.7.2.min.js"></script>
<title>控制台</title>
<script type="text/javascript">

$(document).ready(function(){
// $.ajax({
// type: "POST",
// url: "receiveone.php",
// dataType: "json",
// data: "id=3",
// success: function(data){

// for(var p in data){//遍历json对象的每个key/value对,p为key
// $("select").append("<option value="+data[p].id+">"+data[p].testname+"</option>");
// }
// },
// error:function(){
// alert("F");
// return false;
// }
// });
$.post("receiveone.php",
{
id:3,
},
function(data,status){
for(var p in data){//遍历json对象的每个key/value对,p为key
$("select").append("<option value="+data[p].id+">"+data[p].testname+"</option>");
}
},"json");

});
</script>
</head>
<body>
<input type="text" />
<select name="test">
</select>
<div></div>
</body>
</html>

receiveone.php

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("exam", $con);

// $id=$_POST["id"];
$result=mysql_query("select * from exam_test where subjectid='3'");
$i=0;
while($row = mysql_fetch_array($result))
{
$sum[$i]=$row;
$i++;
}

echo json_encode($sum);
mysql_close($con);

?>

除了数据库,亲测可行

一个php+jquery+json+ajax实例的更多相关文章

  1. 封装一个类似jquery的ajax方法

    //封装一个类似jquery的ajax方法,当传入参数,就可以发送ajax请求 //参数格式如下{ // type:"get"/"post", // dataT ...

  2. Struts2+JQuery+Json登陆实例

    Struts2+JQuery+Json登陆实例 博客分类: Struts2   在搭建之前.. 首先,需要准备struts2.0框架的5个核心包, 以及jsonplugin-0.32.jar 以及js ...

  3. Ajax-05 使用XMLHttpRequest和jQuery实现Ajax实例

    需求: (django)使用XMLHttpRequest和jQuery实现Ajax加法运算 url.py: from django.conf.urls import url from hello im ...

  4. jquery json ajax

    当html中用script包含了不在同一个目录下的js外部文件(主要是为了通用代码的重用)时,这个js文件的 内容就如同在当前html文件中了,写jquery的时候不用考虑路径问题,可以直接引用htm ...

  5. jquery json ajax -2

    如果使用的是虚拟空间, 那么你不能操纵/配置服务器上的php.ini配置文件 但是可以在自己的php文件中, 通过ini_set(...), 和一些对应的函数, 去重置(临时的,仅在当前文件中生效的) ...

  6. JQuery实现AJAX实例

    <script type="text/javascript" src="ReportServer?op=emb&resource=finereport.js ...

  7. 手动模拟一个类似jquery的ajax请求

    var $ = { parms:function(obj){ var str = ''; for(var k in obj){ str +=k+'='+obj[k]+'&'; } str = ...

  8. jquery json ajax三级联动

    province_city_area.jsp <%@ page language="java" pageEncoding="UTF-8"%> < ...

  9. 【JavaScript框架封装】自己动手封装一个涵盖JQuery基本功能的框架及核心源码分享(单文件版本)

    整个封装过程及阅读JQuery源码的过程基本上持续了一个月吧,最终实现了一个大概30%的JQuery功能的框架版本,但是里面涉及的知识点也是非常多的,总共的代码加上相关的注释大概在3000行左右吧,但 ...

随机推荐

  1. kotlin第一个项目的搭建

    怎么在Android Studio中使用Kotlin? 1.使用Android Studio的插件 2.将Android Studio升级到3.0版本:目前不推荐,因为3.0的版本目前还是Dev Ch ...

  2. 【SQL】IN、EXISTS和表连接三者的效率比较

    一. IN和EXISTS比较 在许多基于基础表的查询中,为了满足一个条件,往往需要对另一个表进行查询.此时就会用到IN和EXISTS. 例如:查询departments表中存在的部门的人数. 1. 使 ...

  3. dispatch_sync:As an optimization, this function invokes the block on the current thread when possible

    两件事情: 1.是否是一个线程: 2.queue task 的目标线程是否有未完成的task. 模型:一个线程处理当前的task还有通过gc d派发来的待执行task. 猜测: 如果目标thread上 ...

  4. Unicode转换为UTF-8过程Demo

    碎碎念:这几天在学习Python对Unicode的支持 上学的时候,计算机基础课上总能听到老师讲什么字节,字符,Unicode,UTF-8吧啦吧啦一堆,反正我是只记住了名字,至于具体这些名字所表达的含 ...

  5. react-draft-wysiwyg富文本

      import { EditorState, convertToRaw } from 'draft-js'; import { Editor } from 'react-draft-wysiwyg' ...

  6. 洛谷P1579 哥德巴赫猜想(升级版)【水题+素数】

    1742年6月7日哥德巴赫写信给当时的大数学家欧拉,正式提出了以下的猜想:任何一个大于9的奇数都可以表示成3个质数之和.质数是指除了1和本身之外没有其他约数的数,如2和11都是质数,而6不是质数,因为 ...

  7. nyoj23-取石子(一)

    取石子(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 一天,TT在寝室闲着无聊,和同寝的人玩起了取石子游戏,而由于条件有限,他/她们是用旺仔小馒头当作石子.游戏的 ...

  8. 使用正则表达式爬取500px上的图片

    网址:https://500px.com/seanarcher,seanarcher是一个up主的名字 打开这个网址,会发现有好多图片,具体到每一个图片的url地址 https://500px.com ...

  9. shell脚本编程及bash特性

    bash特性及bash脚本编程初步 终端,附着在终端的接口程序; GUI: KDE,GNome,Xfce CLI: /etc/shells bash的特性: 命令行展开: ~,{} 命令别名: ali ...

  10. PAT 1065. A+B and C

    Given three integers A, B and C in [-263, 263], you are supposed to tell whether A+B > C. Input S ...