¹ØÓÚExt.AjaxÇëÇóPHPµÄÎÊÌâ - Web ¿ª·¢ / Ajax
дÁËÒ»¸öExtµÄAjaxʾÀý,ÆäÖе±ÎÒµÄURL¶¨Ïòµ½ServletµÄʱºò,³É¹¦,·µ»ØÕý³£½á¹û,ÓÃfirebug²é¿´"ÏìÓ¦"²¿·Ö,µÃµ½µÄÊÇÒ»¸öjson×Ö·û´®{data : '11111'}
Ò³Ãæµ÷ÓÃ:
JScript code:
var jsonString = Ext.util.JSON.decode(response.responseText);
Ext.MessageBox.alert("result : ", jsonString.data);
Servlet´úÂë:
Java code:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(username + "\t" + password);
PrintWriter out = response.getWriter();
out.println("{data : '11111'}");
out.flush();
out.close();
}
µ«Êǵ±ÎÒµÄURL¶¨Ïòµ½phpµÄʱºò£¬³É¹¦Êdzɹ¦ÁË,µ«·µ»ØµÄ½á¹ûÊÇÕû¸öPHPÎļþµÄ´úÂë,È»ºóalert³öÀ´ÊÇ¿ÕÖµ,firebugÀïµÄ"ÏìÓ¦²¿·ÖÊÇÕû¸öPHPÎļþµÄ´úÂë,²»ÊÇjson×Ö·û´®",ÒªÔõô×ö²ÅÄÜÄõ½"data"Õâ¸öÖµ?
php´úÂë:
PHP code
Code highlighting produced by Actipro CodeHighlighter
Ïà¹ØÎÊ´ð£º
ÎÒÏÖÔÚÓÃstruts2¿ò¼Ü,ÐèҪʹÓÃajaxʵÏÖ¾Ö²¿Ë¢Ð£¬µ«ÊÇ´ÓÈÝÆ÷Àï·µ»ØµÄÖµ²»ÖªµÀÔõô´Óstruts.xmlÅäÖÃÎļþÀïÓ³Éäµ½jspÒ³ÃæÀÒÔÇ°servletÀïдout.orint("xxxxx")¾Í¿ÉÒԵõ½~£¬µ«ÊÇÏÖÔÚÓÃstruts¾Í²»ÖªµÀÔõôР......
ÎÒÔÚÒ»¸öhtmlÖÐдÈçÏ´úÂ룺
JScript code:
<html>
<head>
<script type="text/javascript" charset="utf-8"
src="script/jquery-1.3.2.min ......
ÕÒÁËÒ»¸ö,µ«ËÑË÷ºó²»Ìáʾ,ºÃÏñÎÊÌâ,²é²»³öÀ´ÔÒò,Ë°ï×Å¿´Ò»ÏÂ
http://www.chinaz.com/Program/Asp/020Q062632010.html
End_rbody_64769658//-->
¸Ã»Ø¸´ÓÚ2010-04-19 08:15:36±»°æÖ÷ɾ³ý
¶ÔÎÒÓÐ ......
´úÂëÈçÏ Çë¸ßÊÖ Ö¸µãÏ лл
ajax_http.js
-------------
function getXMLHTTP() {
var xmlhttp;
if (window.ActiveXObject) {
//IE
try {
......
Çë½Ì¸ßÊÖ°ï棬session_start£¨£©·ÅÔÚÍⲿµÄÎļþÓà require »ò include °üº¬½øÀ´£¬ÇëÎÊÕâÑù×öºÏÀíÂ𣿣¿´úÂëÔËÐÐÊÇÕý³£µÄ£¬ÕâÑù×öºÏÀíÂ𣿣¿Çë¸ßÊÖÖ¸µã¡£¡£¡£¡£ лл····
require »ò include ......