狐狸.fox 2011-12-01 06:38 采纳率: 0%
浏览 30

提交时使用javascript ajax

i am using a google map api to get location. i have used the below function onchange of address field. it is working properly onchange. i have used same function on submit in the same form to checking the function once again while submitting using a onsubmit attribute. but while submitting i cant able to get answer from this ajax because of the that return by using this return true the form submit with pout getting answer.

please any one find a solution for this

function validatePlaceForm(){

            var frm = document.frmOncampus;     

            var oncampusAddress = frm.oncampusAddress.value;

            var xmlhttp;
            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("my_div").innerHTML=''
            var result =xmlhttp.responseText;
                //alert(result);
                var both  =result.split("|");
                    frm.oncampusLatitude.value=both[0];
                    frm.oncampusLongtitude.value=both[1];
            }
          }
            var url='latlog.php?address='+oncampusAddress;

            xmlhttp.open("GET",url,true);
            xmlhttp.send();

            return true;

        }
  • 写回答

3条回答 默认 最新

  • ?yb? 2011-12-01 08:13
    关注

    Change the return value from true to false and call this function like this: onsubmit="return validatePlaceForm();"

    This should do the trick.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办