Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

converting to jquery

Javascript coding ..

Moderators: macek, egami, gesf

converting to jquery

Postby dlopez » 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();
                    }
                else
                    {// code for IE6, IE5
                        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                xmlhttp.onreadystatechange=function()
                    {
                        if (xmlhttp.readyState==4 && xmlhttp.status==200)
                            {
                                document.getElementById("setListSelect").innerHTML=xmlhttp.responseText;
                            }
                     }
                 xmlhttp.open("GET","getNote.php?setListSelect="+option,true);
                 xmlhttp.send();
            }


greatly appreciated!
dlopez
New php-forum User
New php-forum User
 
Posts: 23
Joined: Wed Sep 28, 2011 9:52 am

Re: converting to jquery

Postby rupali » Fri Oct 14, 2011 8:35 pm

Firstly, the basic file : "test.php"

<head>
<script language="javascript" src="jquery-1.6.4.min.js"></script>
<script src="test.js" type="text/javascript">
</script>
</head>
<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">
</form>
<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;

$.ajax({
url:url,
data:datastring,
type:'post',
success:function(data)
{
$(div_id).html(data);
}

});
}

Third you need the output file : test1.php
<?php
if(isset($_POST['t1']))
{
$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
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron