weixin_33713707 2014-04-21 20:43 采纳率: 0%
浏览 31

对JSP页面进行Ajax调用

I am making an ajax call to a jsp page like this :

$(document).ready(function () {
        $('#photo').photobooth().on("image", function (event, dataUrl) {
        alert(dataUrl); 
        //alert($('#mygroupuserid'));
        //alert(document.Clickpictures.OwnerId.value);
        //alert(imgdata);
        $.ajax({
            url: 'uploadwebcamimage.jsp',
            type: "POST",
            data: {
                encodeimg: dataUrl,
                OwnerId: document.Clickpictures.OwnerId.value,
                OwnerPhone: document.Clickpictures.OwnerPhone.value,
                mobilepass: document.Clickpictures.mobilepass.value,
                emailpass: document.Clickpictures.emailpass.value,
                mypassword: document.Clickpictures.mypassword.value,
                mygroupuserid: document.Clickpictures.mygroupuserid.value

            },
            error : function(){ 
                alert('Error'); 
            },
            success: function(msg){      
                    alert(msg);
            }
        });

        $("#gallery").show().html('<img src="' + dataUrl + '" >');
        });
  });

Now in that jsp page i have to make decision basis on some flag value like this :

if(flag==true){

    out.println("<script>alert('Face Successfully Detected and Password has been sent');document.location='Main.jsp'</script>");
    }

    else if(flag==false){

    out.println("<script>alert('Sorry,Face Cant Be Detected.Try Again');</script>");

    }%>

How can this be achieved.?As this alert box is not being printed right Now.Please help

  • 写回答

1条回答 默认 最新

  • elliott.david 2014-04-23 19:45
    关注

    You need to read the parameter values and check them against what you're expecting:

    String ownerId = request.getParameter("OwnerId");
    if("target".equals(ownerId))
    {
      out.println("<script>....");
    }
    

    And to run the Javascript once it is received in the response on the client side, you must use eval(). And you need to fix that missing semi colon in your first JS script.

    评论

报告相同问题?

悬赏问题

  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问