converting to jquery

Javascript coding ..

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 23
Joined: Wed Sep 28, 2011 9:52 am

Fri Oct 14, 2011 8:42 am

I'm attempting to learn some jquery (for ease reasons). I'm having a bit of a hard time grasping how to convert a regular AJAX function to the jquery version... Could anyone show me an example by converting the attached code?

Code: Select all

    function setList(obj)
                var option =obj.title;
                if (window.XMLHttpRequest)
                    {// code for IE7+, Firefox, Chrome, Opera, Safari
                        xmlhttp=new XMLHttpRequest();
                    {// code for IE6, IE5
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                        if (xmlhttp.readyState==4 && xmlhttp.status==200)
greatly appreciated!

New php-forum User
New php-forum User
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Fri Oct 14, 2011 8:35 pm

Firstly, the basic file : "test.php"

<script language="javascript" src="jquery-1.6.4.min.js"></script>
<script src="test.js" type="text/javascript">
<form method="post" action="">
<input type="text" name="t1" id="t1">
<input type="text" name="t2" id="t2">
<input type="button" onclick="abcode()" value="save">
<div id="green"></div>

Secondly, the javascript file : "test.js"

function abcode()
var t1=document.getElementById("t1").value;
var t2=document.getElementById("t2").value;

var url="test1.php";
var div_id='#green';
var datastring='t1='+t1+'&t2='+t2;



Third you need the output file : test1.php
$a = $_POST['t1'];
$b = $_POST['t2'];

echo "Textbox1 is ".$a."<br/>";
echo "Textbox2 is ".$b;


OUTPUT : localhost/test.php

For example, in textbox1 value entered is a and in textbox2 value entered is b

output is,
Textbox1 is a
Textbox2 is b

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests