populating from database and autofill textboxes using ajax,php - php

I am facing a small problem regarding this topic.I had write a code to autofill textboxes from database values when I type a id value in the previous textfield.i.e.if I type userid,the next textfields will autofill from database without refresh in ajax and php.my problem is that I cant find the error in my code.help me to find out.Here is my code:
**a.html**
<!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=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
var url = "getagentids.php?param=";
function handleHttpResponse() {
if (http.readyState == 4) {
results = http.responseText.split(",");
document.getElementById('agfn').value = results[0];
document.getElementById('agsal').value = results[1];
document.getElementById('agtel').value = results[2];
document.getElementById('agid').value = results[3];
}
}
function getagentids() {
var idValue = document.getElementById("agid").value;
var myRandom=parseInt(Math.random()*99999999); // cache buster
http.open("GET", url + escape(idValue) + "&rand=" + myRandom, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
function getHTTPObject() {
var xmlhttp;
/*#cc_on
#if (#_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
#else
xmlhttp = false;
#end #*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
</script>
</head>
<body>
<form name="schform">
<table>
<tr>
<td>Contact ID:</td>
<td><input id="agid" type="text" name="contactid" onKeyUp="getagentids();"></td>
</tr><tr>
<td>Tel Number:</td> <td><input id="agtel" type="text" name="contacttel"></td>
</tr><tr>
<td>Name:</td> <td><input id="agfn" type="text" name="contactfullname"></td>
</tr><tr>
<td>Salutation:</td> <td><input id="agsal" type="text" name="contactsalutation"></td>
</tr>
<tr> <td><input type="reset" value="Clear"></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
**getagentids.php**
<?php
$link = mysql_connect('localhost', 'arbiocua_mita', 'asd123$');
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('arbiocua_monomita');
//$param=intval($_GET['contactid']);
if(strlen($param)>0)
{
$result = mysql_query("SELECT ContactFullName, ContactSalutation, ContactTel FROM contact WHERE ContactID LIKE '$param%'");
if(mysql_num_rows($result)==1)
{
while($myrow = mysql_fetch_array($result))
{
$agentname = $myrow["ContactFullName"];
$agenttel = $myrow["ContactTel"];
$agentsal = $myrow["ContactSalutation"];
$agentid = $myrow["ContactID"];
$textout = $agentname.",".$agentsal.",".$agenttel.",".$agentid;
} }
else { $textout=" , , ,".$param;
} }
echo $textout;
?>
**database**:
table name 'contact'
ContactID ContactFullName ContactSalutation ContactTel

$textout=json_encode($textout)
Then echo $textout

Related

PHP setting JSON values to Textboxes

This is the html file.
<html>
<head>
<script>
function showUser(str) {
if (str == "") {
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var doc = window.document.createElement("doc");
var a = JSON.parse(xmlhttp.responseText);
document.getElementById("stuname").value=a.first;
document.getElementById("branch").value=a.second;
document.getElementById("year").value=a.third;
document.getElementById("category").value=a.four;
}
}
xmlhttp.open("GET","test2.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form>
Roll Number:<br>
<input type="text" name="rollno" id="rollno" onblur="showUser(this.value)">
<br>
Student Name:<br>
<input type="text" name="stuname" id="stuname" value="">
Branch:<br>
<input type="text" name="branch" id="branch" value="">
Year:<br>
<input type="text" name="year" id="year" value="">
Category:<br>
<input type="text" name="category" id="category" value="">
</form>
<br>
</body>
</html>
test2.php file
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$q = $_GET['q'];
$con=mysqli_connect("localhost","root","neel","sitams");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT rollno,stuname,branch,category FROM studet where rollno='".$q."' and academic='2014-2015'";
if ($result=mysqli_query($con,$sql))
{
while ($obj=mysqli_fetch_object($result))
{
$queryResult[] = $obj->rollno;
$queryResult[] = $obj->stuname;
$queryResult[] = $obj->branch;
$queryResult[] = $obj->category;
}
}
$textboxValue1 = $queryResult[0];
$textboxValue2 = $queryResult[1];
$textboxValue3 = $queryResult[2];
$textboxValue4 = $queryResult[3];
echo json_encode(array('first'=>$textboxValue1,'second'=>$textboxValue2,'third'=>$textboxValue3,'four'=>$textboxValue4));
?>
</body>
</html>
I could not able to load values to the text boxes where is fault. Even I have seen stackoverflow but I could not able to get it. when I type test2.php by passing rollno value to q it will display data but when I pass a value from html it could not able to set the values to the textbox fields.
Remove any html tags from test2.php . An ajax document does not need any html tags.
Hi this one will be helpful to you .
<html>
<head>
</head>
<body>
<input type="button" onclick="showUser('ok');" value="click to ru me" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
function showUser(str)
{
if (str=="")
{
return;
}
else
{
if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); }
else { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
//var doc = window.document.createElement("doc");
var parsed = JSON.parse(xmlhttp.responseText);
for(var x in parsed)
{
var First=parsed[x].first;
var Second=parsed[x].second;
var Third=parsed[x].third;
var Fourth=parsed[x].fourth;
console.log("first="+First+" second="+Second+" third="+Third+" fourth="+Fourth);
document.getElementById("stuname").value=parsed[x].first;
document.getElementById("branch").value=parsed[x].second;
document.getElementById("year").value=parsed[x].third;
document.getElementById("category").value=parsed[x].fourth;
}
}
}
xmlhttp.open("GET","phpex.php?q="+str,true);
xmlhttp.send();
}
}
</script>
<input type="text" id="stuname" />
<input type="text" id="branch" />
<input type="text" id="year" />
<input type="text" id="category" />
</body>
</html>
Ajax File Name phpex.php . ajax page code is below
<?php
echo '[{"first":"1111","second":"2222","third":"3333","fourth":"4444"}]';
?>

How to insert into MySQL HTML Form data?

I checked a lot of articles and I don't understand it how to insert data into a MySQL table. What is wrong? I guess that my Ajax request is already wrong.
I would be happy to get help!!!
I did not write programs since 20 years. My coding is for sure not good, but I need to get it running.
Any help would be very appreciated!
The code that follows does not INSERT INTO and does not UPDATE. Why?
Here is the source:
articles.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" dir="ltr" lang="en-US">
<head>
<meta charset="UTF-8" />
<title>SoB - Administration</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/scroll.js"></script>
<script type="text/javascript" src="js/producttemplate.js"></script>
<script type="text/javascript" src="js/jquery.js" ></script>
<style type="text/css">.buttonarea: (\a)</style>
<script type="text/javascript">
<!--
var js_string;
document.getElementById("recordWrite").disabled = true;
var lastPreviousNext = "";
var date = new Date();
var mysqlDateTime;
var yyyy = date.getFullYear();
var mm = date.getMonth() + 1;
var dd = date.getDate();
var hh = date.getHours();
var min = date.getMinutes();
var ss = date.getSeconds();
mysqlDateTime = yyyy + '-' + mm + '-' + dd + ' ' + hh + ':' + min + ':' + ss;
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// No submit by onclick
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
elem = document.getElementById('buttonID');
function stop(e) {
e.preventDefault(); // browser - don't act!
e.stopPropagation(); // bubbling - stop
return false; // added for completeness
}
elem.addEventListener('click', stop, false);
// this handler will work
elem.addEventListener('click', function() { alert('I still work') }, false);
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function jsRecordInsertWrite()
{
document.getElementById('formheadline').innerHTML = 'Article Database - I save the new item';
document.getElementById("recordWrite").disabled = true;
js_articles[0]=""; // set auto increment id to NULL
// ... the AJAX request is successful
var updatePage = function (response) {
alert("insert record successful");
};
// ... the AJAX request fail
var printError = function (req, status, err) {
alert("insert record failed");
};
// Create an object to describe the AJAX request
var ajaxOptions = {
url: 'writearticle.php',
dataType: 'json',
success: updatePage,
error: printError
};
// Initiate the request!
$.ajax(ajaxOptions);
}
// -->
</SCRIPT>
</head>
<body class="page page-id-11505 page-template-default" onload="jsRecordCurrent();">
<div id="page-wrap">
<?php
include('includes/header.html');
?>
<div id="container-main">
<div id="main-content">
<div class="post" id="post-11505">
<title>SoB - Administration</title>
<div class="entry">
<form id="form_articles" method="post" action="<?= $_SERVER['PHP_SELF'] ?>" name="form_articles">
<table border="0" cellpadding="0" cellspacing="5">
<tr>
<td align="right">
<span style="padding-right:20px">Item</span>
</td>
<td>
<input id="Item" name="Item" type="text" maxlength="100" size="25"/>
</td>
</tr>
<tr>
<td align="right">
<span style="padding-right:20px">Item Category</span>
</td>
<td>
<input name="ItemCategory" type="text" maxlength="100" size="25" />
</td>
</tr>
<tr id="buttonarea">
<td align="right" colspan="2">
<hr noshade="noshade" />
<input id="recordInsertWrite" type="button" name="recordInsertWrite" value=" Save New Record " onclick="jsRecordInsertWrite()" />
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
<div id="aside">
</div>
</div> <!-- End of main container -->
</div><!-- END Page Wrap -->
</body>
</html>
writearticle.php
<?php
$link = mysql_connect('test.test.com:3306', 'admin0', 'star1star1star0');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('sob', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
// Escape user inputs for security
$ID = mysql_real_escape_string($_POST['ID']);
$Item = mysql_real_escape_string($_POST['Item']);
$ItemCategory = mysql_real_escape_string($_POST['ItemCategory']);
if('$ID' == '')
{
$sql = "INSERT into articles values(NULL,'$Item','$ItemCategory')";
$query = mysql_query($sql);
if(!$query)
{
echo '<script type="text/javascript">alert("error");</script>';
}
else
{
echo '<script type="text/javascript">alert("ok");</script>';
}
}
else
{
$sql = "UPDATE articles SET Item='$Item',ItemCategory='$ItemCategory')";
$query = mysql_query($sql);
if(!$query)
{
echo '<script type="text/javascript">alert("update error");</script>';
}
else
{
echo '<script type="text/javascript">alert("update ok");</script>';
}
}
?>

Ajax search not Working whereas the XML already running?

I'm a newbie on Ajax, I have tried the tutorial Book, but it did not work. The code is for searching.
This is the script search.htm
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AJAX + MySQL I</title>
<script type="text/javascript" src="search.js"></script>
</head>
<body onload='process()'>
<h1>Student Search</h1>
<form name="form1">
Masukkan Nama Mahasiswa: <input type="text" id="namaMhs" />
</form>
<p><strong>Hasil Pencarian :</strong></p>
<div id="hasil" />
</body>
</html>
and the JS script search.js
var xmlHttp = createXmlHttpRequestObject();
function createXmlHttpRequestObject()
{
var xmlHttp;
if(window.ActiveXObject)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
xmlHttp = false;
}
}
else
{
try
{
xmlHttp = new XMLHttpRequest();
}
catch (e)
{
xmlHttp = false;
}
}
if (!xmlHttp) alert("Obyek XMLHttpRequest tidak dapat dibuat");
else
return xmlHttp;
}
function process()
{
if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
{
nama =
encodeURIComponent(document.getElementById("namaMhs").value);
xmlHttp.open("GET", "search.php?namaMhs=" + nama, true);
xmlHttp.onreadystatechange = handleServerResponse;
xmlHttp.send(null);
}
else
setTimeout('process()', 1000);
}
function handleServerResponse()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
var xmlResponse = xmlHttp.responseXML;
xmlRoot = xmlResponse.documentElement;
nimArray = xmlRoot.getElementsByTagName("nim");
namaMhsArray = xmlRoot.getElementsByTagName("namamhs");
alamatArray = xmlRoot.getElementsByTagName("alamat");
if (nimArray.length == 0)
{
html = "Data tidak ditemukan";
}
else
{
// membentuk tabel untuk menampilkan hasil pencarian
html = "<table border='1'><tr><th>NIM</th><th>Nama
Mhs</th><th>Alamat</th></tr>";
for (var i=0; i<nimArray.length; i++)
{
html += "<tr><td>" + nimArray.item(i).firstChild.data +
"</td><td>" +
namaMhsArray.item(i).firstChild.data +
"</td><td>" +
alamatArray.item(i).firstChild.data +
"</td></tr>";
}
html = html + "</table>";
}
document.getElementById("hasil").innerHTML = html;
setTimeout('process()', 1000);
}
else
{
alert("Ada masalah dalam mengakses server: " +
xmlHttp.statusText);
}
}
}
and the last script in php search.php
<?php
header('Content-Type: text/xml');
echo '<hasil>';
$namaMhs = $_GET['namaMhs'];
mysql_connect("localhost","root","*******");
mysql_select_db("mahasiswa");
$query = "SELECT * FROM mhs WHERE namamhs LIKE '%$namaMhs%'";
$hasil = mysql_query($query);
while ($data = mysql_fetch_array($hasil))
{
echo "<mhs>";
echo "<nim>".$data['NIM']."</nim>";
echo "<namamhs>".$data['NAMAMHS']."</namamhs>";
echo "<alamat>".$data['ALAMAT']."</alamat>";
echo "</mhs>";
}
echo '</hasil>';
?>
Please help me to fix this script. The XML on search.php is already running but my searching is not. Any help is appreciated.
You are submitting the script on load, before there is even a value in the text field:
<body onload='process()'>
<h1>Student Search</h1>
<form name="form1">
Masukkan Nama Mahasiswa: <input type="text" id="namaMhs" />
</form>
You should either add a value to the text field as such:
<input type="text" value="testname" id="namaMhs" />
Or as a better option, add a submit button and don't run the function on load, but rather on submit:
<body>
<h1>Student Search</h1>
<form name="form1">
Masukkan Nama Mahasiswa: <input type="text" id="namaMhs" />
<input type="button" value="Search" onclick="process();" />
</form>
There may be more or even many more problems with your code, I am not looking through it all, but this should get you off to a good start.

ajax post method and php

Ho all, here I explain my problem (as far as i red i didnt find any working solution).
here I link my files:
progetto.html
<html>
<head>
<script type="text/javascript" src="funzioni.js"></script>
<title>Pagina iniziale</title>
</head>
<body align='center'>
<p>Gymnasium</p>
<p>icona</p>
<form id="ajaxForm" name="ajaxForm">
<table align="center">
<tr>
<td><label>Utente</label></td>
<td><input type="text" name="user" id="user" value="" /></td>
</tr>
<tr>
<td><label>Password</label></td>
<td><input type="password" name="password" id="password" value="" /></td>
</tr>
</table>
<input type="button" id="submit" name="submit" value="Accedi" onclick='submitForm()' />
</form>
<div id="risultato"></div>
</body>
javascript file
function createXMLHttpRequestObject(){
if (window.XMLHttpRequest) { return new XMLHttpRequest(); }
if (window.ActiveXObject) { return new ActiveXObject(Microsoft.XMLHTTP); }
return null;
}
function submitForm(){
var ajax = createXMLHttpRequestObject();
ajax.onreadystatechange = function () {
if (ajax.readyState==4 && ajax.status==200){
var response = ajax.responseText;
document.getElementById("risultato").innerHTML = response;
}
}
ajax.open("post", "ajaxLogin.php", true);
var data = "utente=" + document.getElementById('user').value + "&password=" + document.getElementById('password').value;
ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajax.send(data);
}
ajaxLogin.php
<?php
if (!isset($_POST["user"]) || !isset($_POST["password"])){
die("Bad login");
}
$user = $_POST['user'];
$pwd = $_POST['password'];
if ( (($user == "angel") && ($pwd == "devil")) || (($user == "john") && ($pwd == "smith")) ){
$response = "Benvenuto " . $user;
echo $response;
}
?>
Problem is I always receive Bad Login message even if I use the right user and password.
It's a POST problem with I'm really having hard time figuring out the solution.
This is your data:
var data = "utente=" + document.getElementById('user').value + "&password=" + document.getElementById('password').value;
And this is what you are checking:
if (!isset($_POST["user"]) || !isset($_POST["password"])){
You should change utente to user or the other way around. In your form you are using user as well so I would recommend using that everywhere.
So:
var data = "user=" + document.getElementById('user').value + "&password=" + document.getElementById('password').value;

How to post the parameter to the php logincheck.php

This is my simple form which contains employe name, empno, empsal and doj(date of joining). Here i'm posting the values of this form through XMLHttpRequest object through send asynchronously and updating the requestTxt in the DOM in myDiv.
Here when i pass the parameters some thing like this, i can able to get the values in php echo $empname. "is my name";
var params = "empname="+myname+"&empno="+myno+"&empsal="+mysal+"&empdoj="+mydoj;
But at the same time, if i pass it as a object, stringified i don't know why it is not printing
var params = {
"empname":myname,
"empno":myno,
"empsal":mysal,
"empdoj":mydoj
};
var jsonText = JSON.stringify(params);
alert(jsonText);
Here is my code
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="windows-1252">
<title>Sample form</title>
<style>
table td{
border-collapse:collapse;
border:1ps solid #000;
}
.hide{
display:none;
}
</style>
<script type="text/javascript" src="util.js"></script>
</head>
<body>
<form name="sampleForm" id="sampleForm" action="javascript:return false;">
<table width="40%">
<tr>
<td>Employee Name:</td>
<td><input type="text" name="empname" id="empname"/></td>
</tr>
<tr>
<td>Employee No:</td>
<td><input type="text" name="empno" id="empno"/></td>
</tr>
<tr>
<td>Employee salary:</td>
<td><input type="text" name="empsal" id="empsal"/></td>
</tr>
<tr>
<td>Employee DOJ:</td>
<td><input type="text" name="empdoj" id="empdoj"/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submitBtn" id="submitBtn1" /></td>
</tr>
</table>
<div class="hide" id="myDiv"></div>
</form>
<script type="text/javascript">
var subform = document.getElementById("sampleForm");
subform.onsubmit = function(){
var myReq;
var uRLTxt = "loginCheck.php";
var myname = document.getElementById("empname").value;
var myno = document.getElementById("empno").value;
var mysal = document.getElementById("empsal").value;
var mydoj = document.getElementById("empdoj").value;
/*var params = "empname="+myname+"&empno="+myno+"&empsal="+mysal+"&empdoj="+mydoj; */
var params = {
"empname":myname,
"empno":myno,
"empsal":mysal,
"empdoj":mydoj
};
var jsonText = JSON.stringify(params);
alert(jsonText);
myReq = new XMLHttpRequest();
myReq.open("POST",uRLTxt,true);
myReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//myReq.setRequestHeader("Content-type", "application/JSON; charset=utf-8");
myReq.setRequestHeader("Content-length", jsonText.length);
//alert(jsonText.length);
myReq.setRequestHeader("Connection", "close");
myReq.onreadystatechange = function() {
if(myReq.readyState == 4 && myReq.status == 200){
var return_data = myReq.responseText;
console.log(return_data);
document.getElementById("myDiv").style.display = "block";
document.getElementById("myDiv").innerHTML = return_data;
}
}
myReq.send(jsonText);
return false;
};
</script>
</body>
</html>
Php Code - loginCheck.php
<?php
$empname = isset($_REQUEST['empname']);
$empno = isset($_REQUEST['empno']);
$empsal = isset($_REQUEST['empsal']);
$empdoj = isset($_REQUEST['empdoj']);
echo $empname."is my name";
?>
If you want to use javascript alone,
you want to specify the data you want to send in the send() method.
var params = {
"empname":myname,
"empno":myno,
"empsal":mysal,
"empdoj":mydoj
};
var jsonText = JSON.stringify(params);
myReq.send("totalJsonStr="+jsonText);
Decode your json string using json_decode() . Add this to your loginCheck.php
<?php
if(isset($_POST["totalJsonStr"])) {
$jsonVal = json_decode($_POST["totalJsonStr"]);
//If you want empname
print $jsonVal->{'empname'} . " is my name"; }
else { die("No Data Found"); }
?>
Try it,
<script language="javascript" src="jquery-1.4.4.min.js"></script>
<script>
var myname = document.getElementById("empname").value;
var myno = document.getElementById("empno").value;
var mysal = document.getElementById("empsal").value;
var mydoj = document.getElementById("empdoj").value;
var subform = document.getElementById("sampleForm");
subform.onsubmit = function(){
$.ajax({
url: 'loginCheck.php', //This is the current doc
type: "POST",
dataType:'json', // add json datatype to get json
data:"empname=myname&empno=myno&empsal=mysal&empdoj=mydoj",
success: function(data){ alert(data); })
}, }); };
</script>
Your PHP looks like this:
<?php
$empname = isset($_REQUEST['empname']);
$empno = isset($_REQUEST['empno']);
$empsal = isset($_REQUEST['empsal']);
$empdoj = isset($_REQUEST['empdoj']);
echo $empname."is my name";
?>
But the function isset() only returns true or false, depending if a variable is set or not. Your script should look like:
<?php
// Repeat for all variables
// This is an equivalent to:
// if (isset($_REQUEST['empname'])) {
// $empname = $_REQUEST['empname'];
// }
// else {
// $empname = "";
// }
$empname = isset($_REQUEST['empname']) ? $_REQUEST['empname'] : "";
echo "{$empname} is my name";
?>
For your params string in Javascript, change this:
var params = {
"empname":myname,
"empno":myno,
"empsal":mysal,
"empdoj":mydoj
};
var jsonText = JSON.stringify(params);
alert(jsonText);
// Blah blah...
myReq.send(jsonText);
for this:
var params = {
"empname":myname,
"empno":myno,
"empsal":mysal,
"empdoj":mydoj
};
var out = new Array();
for (key in params) {
out.push(key + "=" + encodeURI(params[key]));
}
var postText = out.join("&");
alert(postText);
// Blah blah...
myReq.send(postText);

Categories