ajax无刷新判断某公司是否包含某业务

前端之家收集整理的这篇文章主要介绍了ajax无刷新判断某公司是否包含某业务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.jsp页面

  1. <form action="market.do?enter=creaditApplyForAdd" method="post" name="form1">
  2. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  3. <tr>
  4. <td bgcolor="f7f7f7">
  5. <table width="100%" >
  6. <tr>
  7. <td colspan="4" align="left" width="100%" bgcolor="LightGrey" ><strong>[::第三方信控业务申请详细信息::]</strong></td>
  8. </tr>
  9. <tr>
  10. <td align="right" width="20%" bgcolor="LightGrey" >第三方登陆用户名: </td>
  11. <td align="left" width="30%"><input type="text" id="user_name" name="USER_NAME" readonly="readonly"><input Class="input_btn" type="button" value="选择" onclick="openShowModal('../market/market.do?enter=getCreditUserlist',940,400);"><font color="red"> *</font></td>
  12. <td align="right" width="20%" bgcolor="LightGrey" >SP名称:</td>
  13. <td align="left" width="30%"><input type="text" id="sp_name" name="SP_NAME" readonly="readonly"></td>
  14. </tr>
  15. <tr>
  16. <td align="right" width="20%" bgcolor="LightGrey" >第三方业务号: </td>
  17. <td align="left" width="30%"><input type="text" id="pd_id" name="PD_ID" readonly="readonly"><input Class="input_btn" type="button" value="选择" onclick="getlist()"><font color="red"> *</font></td>
  18. <td align="right" width="20%" bgcolor="LightGrey" >第三方业务名称:</td>
  19. <td align="left" width="30%"><input type="text" id="bus_name" name="BUS_NAME" readonly="readonly"></td>
  20. </tr>
  21. <tr>
  22. <td align="right" width="20%" bgcolor="LightGrey" >产品名称:</td>
  23. <td align="left" width="30%"><input type="text" id="proc_name" name="PROC_NAME" readonly="readonly"></td>
  24. <td align="right" width="20%" bgcolor="LightGrey" >基本资费:</td>
  25. <td align="left" width="30%"><input type="text" id="proc_fee" name="PROC_FEE" readonly="readonly"></td>
  26. </tr>
  27. <table align="center" border="0" >
  28. <tr >
  29. <td width="61" align="center">
  30. </td>
  31. <td align="center" width="84">
  32. </td>
  33. <td width="78" align="center">
  34. <table width="75" border="0" cellspacing="0" cellpadding="0">
  35. <tr>
  36. <td width="316" align="left">
  37. <input class="input_btn" type="button" value="添 加" style="font-weight: bold" onclick="dosubmit()"/><input class="input_btn" type="button" value="关 闭" style="font-weight: bold" onClick="javascript:window.close();"/>
  38. </td>
  39. </tr>
  40. </table>
  41. </td>
  42. <td width="144">
  43. </td>
  44. <td width="0">
  45. </td>
  46. </tr>
  47. </table>
  48. </td>
  49. </tr>
  50. </table>
  51. </form>


2.javascript(ajax方法

@H_301_24@
  1. function dosubmit() {
  2. var username = document.getElementById("user_name").value;
  3. var pdid=document.getElementById("pd_id").value;
  4. var xmlHttp;
  5. //根据不同浏览器初始化xmlHttp
  6. try {
  7. //IE 6+
  8. xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  9. } catch (e) {
  10. try {
  11. //FireFox
  12. xmlHttp = new XMLHttpRequest();
  13. } catch (e) {
  14. try {
  15. //IE 5.5+
  16. xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  17. } catch (e) {
  18. alert("您的浏览器不支持Ajax!");
  19. }
  20. }
  21. }
  22. xmlHttp.open("POST", "market.do?enter=check&username=" + username+"&pdid="+pdid,true);
  23. xmlHttp.send(null);
  24. xmlHttp.onreadystatechange = function() {
  25. if (xmlHttp.readyState == 4) {
  26. var message=xmlHttp.responseText;
  27. if(message=='已存在'){
  28. alert("已经有此业务");
  29. return;
  30. }else{
  31. var fom = document.forms[0];
  32. fom.submit();
  33. }
  34. }
  35. }
  36. }

2.java后台方法(这里的msg对应上面jsp页面xmlHttp.responseText的内容


  1. public ActionForward check(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {
  2. response.setContentType("text/xml;charset=GB2312");
  3. response.setHeader("Cache-Control","no-cache");
  4. String username = request.getParameter("username");
  5. String pdid=request.getParameter("pdid");
  6. List list = cmng.check(username,pdid);
  7. String msg="不存在";
  8. if(list.size()>0){
  9. msg="已存在";
  10. }
  11. try {
  12. response.getWriter().print(msg);
  13. response.getWriter().close();
  14. } catch (IOException e) {
  15. // TODO Auto-generated catch block
  16. e.printStackTrace();
  17. }
  18. return null;
  19. }

猜你在找的Ajax相关文章