jQuery excellent Javascript is a framework for a good js packaging, provides a lot of convenient features. jQuery for ajax packaging can be called outstanding.
jQuery can json file transfer protocol to transmit data (similar to xml, but also significant trend to replace the xml), while the site background code must be used in conjunction with them. PHP is used json_encode function to return an array of encoded data, but this function is only supported PHP5.2 version above.
Json from the Internet to find a type of operation, I PHP4.4.7 version at the next test. I also built a function function my_json_encode ($ phparr), so that code-compatible version of PHP5.2 above.
Sample code (including the type of json package software) can be download at the following URL: http://download.csdn.net/source/810895
Following is the full code:
<html>
<head>
Examples <title> jQuery Ajax Demo </ title>
</ head>
<script language="javascript" src="../lib/jquery.js"> </ script>
<script language="javascript">
$ (document). ready (function ()
(
$ ( # send_ajax). click (function () (
var params = $ ( input). serialize (); / / serialization of the value of the form
$. ajax ((
url: ajax_json.php, / / background processing procedures
type: post, / / data distribution methods
dataType: json, / / accept the data format
data: params, / / to pass on data
success: update_page / / return function (here is the function name)
));
));
/ / $. post () method:
$ ( # test_post). click (function () (
$. post (
ajax_json.php,
(
username :$(# input1 ). val (),
age :$(# input2 ). val (),
sex :$(# input3 ). val (),
job :$(# input4 ). val ()
),
function (data) / / return function
(
var myjson =;
eval ( amyjson = + data +;);
$ ( # result). html ( "Name:" + myjson.username + "<br/> job:" + myjson [ job]);
)
);
));
/ / $. get () method:
$ ( # test_get). click (function ()
(
$. get (
ajax_json.php,
(
username :$("# input1 "). val (),
age :$("# input2 "). val (),
sex :$("# input3 "). val (),
job :$("# input4 "). val ()
),
function (data) / / return function
(
var myjson =;
eval ( "myjson =" + data + ";");
$ ( "# result"). html (myjson.job);
)
);
));
));
function update_page (json) / / return function entity, the parameters for XMLhttpRequest.responseText
(
var str = "Name:" + json.username + "<br />";
str + = "age:" + json.age + "<br />";
str + = "gender:" + json.sex + "<br />";
str + = "job:" + json.job + "<br />";
str + = "additional tests:" + json.append;
$ ( "# result"). html (str);
)
</ script>
<body>
<div> </ div>
<form action="" method="post">
<p> <span> input name: </ span> <input type="text" name="username" /> </ p>
<p> <span> enter age: </ span> <input type="text" name="age" /> </ p>
gender <p> <span> input: </ span> <input type="text" name="sex" /> </ p>
<p> <span> input job: </ span> <input type="text" name="job" /> </ p>
</ form>
<button> submit </ button>
<button> POST submit </ button>
<button> GET submit </ button>
</ body>
</ html>
PHP file ajax_json.php:
<? php
/ / $ arr = $ _POST; / / if $. get () methods to send data, will be changed to $ _GET. or simply: $ _REQUEST
$ arr = $ _REQUEST;
$ arr [ append] = est string;
/ / print_r ($ arr);
$ myjson = my_json_encode ($ arr);
echo $ myjson;
function my_json_encode ($ phparr)
(
if (function_exists ( "json_encode"))
(
return json_encode ($ phparr);
)
else
(
require_once json / json.class.php;
$ json = new Services_JSON;
return $ json-> encode ($ phparr);
)
)
?>
Related Stuff
-
MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.
-
Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone
-
TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support
-
ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.
-
Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.
-
Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software
- PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Original Source: