简体   繁体   English

ajax查询无法正常工作

[英]ajax query not working properly

<body style="margin:0px; padding:0px;" >
            <form method="post" >
              <input type="text" id="city" name="city" placeholder="city">
              <input type="submit"  value="Search" id="searchid"/>
            </form>
        <script>
           $("#searchid").click(function() {
           var city=$("#city").val();
           $.ajax({
           type:'POST',
           data:city,
           url:'mm.php',
           success:function(data) {
           alert(data);
             }
            });
          });
         </script> 

I am new to javascript.I want to search a city in google map using ajax query.But my ajax query is not working properly.It does not opening the given url. 我是javascript新手,我想使用ajax查询在google map中搜索城市。但是我的ajax查询无法正常工作。它无法打开给定的url。

Your Submit button is inside an html form. 您的“提交”按钮位于html表单内。 When you click this button you need to prevent the entire form to be posted, in order to be able to run your Ajax instead. 单击此按钮时,需要阻止整个表单发布,以便能够运行Ajax。 Try this... 尝试这个...

<input type="submit" value="Search" id="searchid" onclick="javascript: return false;" />

Apart from that, what Mayk pointed out is also correct. 除此之外,Mayk指出的也是正确的。 The parameter for sending city needs to have a name. 发送城市的参数需要有一个名称。 With these two changes your code worked for me when calling an Http Handler created in .Net. 通过这两个更改,您的代码在调用.Net中创建的Http Handler时对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM