function load XMLDoc var xmlhttp if window XMLHttp

  • Slides: 6
Download presentation
function load. XMLDoc() { var xmlhttp; if (window. XMLHttp. Request) {// code for IE

function load. XMLDoc() { var xmlhttp; if (window. XMLHttp. Request) {// code for IE 7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttp. Request(); } else {// code for IE 6, IE 5 xmlhttp=new Active. XObject("Microsoft. XMLHTTP"); } xmlhttp. onreadystatechange=function() { if (xmlhttp. ready. State==4 && xmlhttp. status==200) { document. get. Element. By. Id("my. Div"). inner. HTML=xmlhttp. response. Text; } } xmlhttp. open("GET", "ajax_info. txt", true); xmlhttp. send(); } </script></head><body> <div id="my. Div"><h 2>Let AJAX change this text</h 2></div> <button type="button" onclick="load. XMLDoc()">Change Content</button>

AJAX WITH COUNTRY, CITY AND STATE APPLICATION public class Connection. Demo �{ � public

AJAX WITH COUNTRY, CITY AND STATE APPLICATION public class Connection. Demo �{ � public static Connection get. My. Sql. Connection()throws Exception � { � String driver="com. mysql. jdbc. Driver"; � String url="jdbc: mysql: //localhost: 3306/piet"; � String user="root"; � String password = "root"; � Connection con = null; � Class. for. Name(driver); � con = Driver. Manager. get. Connection(url, user, password); � return con; � } �} �

country. jsp: <script type="text/javascript" language="text/javascript"> var xmlhttp; function show. State(str) { if(window. XMLHttp. Request)

country. jsp: <script type="text/javascript" language="text/javascript"> var xmlhttp; function show. State(str) { if(window. XMLHttp. Request) { xmlhttp = new XMLHttp. Request(); } else if(window. Active. XObject) { xmlhttp = new Active. XObject("Microsoft. XMLHTTP"); } var url="state. jsp"; url = url+"? count="+str; xmlhttp. onreadystatechange = state. Change; xmlhttp. open("GET", url, true); xmlhttp. send(); } function state. Change() { if(xmlhttp. ready. State==4 ||xmlhttp. status==200) { document. get. Element. By. Id("state"). inner. HTML = xmlhttp. response. Text; � } � � � � � �

<select name="country" onchange="show. State(this. value)"> <option value="none">Select</option> <% Connection con = Connection. Demo. get.

<select name="country" onchange="show. State(this. value)"> <option value="none">Select</option> <% Connection con = Connection. Demo. get. My. Sql. Connection(); Statement stmt = con. create. Statement(); Result. Set rs = stmt. execute. Query("select *from country"); while(rs. next()) { %> <option value="<%= rs. get. String(1)%>"><%=rs. get. String(2) %></option> <% } %> </select> <div id='state'> <select name="state"> <option value="-1"></option> </select> </div>

state. jsp: <%@page import="com. sdj. Connection. Demo"%> <html><head></head><body> <% String county = request. get.

state. jsp: <%@page import="com. sdj. Connection. Demo"%> <html><head></head><body> <% String county = request. get. Parameter("count"); String buffer = "<select name='state' onchange='show. City(this. value); '><option value='-1'>Select</option>"; Connection con = Connection. Demo. get. My. Sql. Connection(); Statement stmt = con. create. Statement(); Result. Set rs = stmt. execute. Query("select *from state where countryid='"+county+"'"); while(rs. next()) { buffer = buffer + "<option value='"+rs. get. String(1)+"'>"+rs. get. String(3)+"</option>"; } buffer = buffer +"</select>"; response. get. Writer(). println(buffer); %>