Form submit with geocomplete jquery geocoding doesn't POST latitude & longitude

佐手、 提交于 2019-12-13 07:05:02

问题


I am using http://ubilabs.github.com/geocomplete/ to have a form submit latitude & longitude. If I just do the trigger below it works and fills up lat & lng fields. However, when I add the submit jquery code, it submits blank fields. I know its some timing thing since I can see the fields fill up but not sent via POST. But I can't figure it out, any suggestions?

<script>
  $(document).ready(function(){
  // Area for any jQuery
    $("#geocomplete").geocomplete({
      details: "form",
      types: ["geocode", "establishment"]
    });

    $("#geoform").submit(function() {
      $("#geocomplete").trigger("geocode");
      alert('Handler for .submit() called.');
      return true;
    });
  });
</script>


<form id="geoform" method=post action="/foo.php">
  <input id="geocomplete" type="text" placeholder="Type in an address" value="Empire State Bldg" />
  <!--<input id="find" type="button" value="find" />-->
  <input type="submit" value="Go" />

  <fieldset>
    <input name="lat" type="text" value="">
    <input name="lng" type="text" value="">
    <input name="query" type="hidden" value="true">
  </fieldset>
</form>

回答1:


I removed the trigger from the submit function and I added a delay.

<script>

      $(document).ready(function(){
      // Area for any jQuery
        $("#geocomplete").geocomplete({
          details: "form",
          types: ["geocode", "establishment"]
        });

        $("#submit-button").click(function() {
          $("#geocomplete").trigger("geocode");
          setTimeout("$('#geoform').submit();",500);
        });
      });
    </script>


    <form id="geoform" method=post action="/foo.php">
      <input id="geocomplete" type="text" placeholder="Type in an address" value="Empire State Bldg" />
      <!--<input id="find" type="button" value="find" />-->
      <input id="#submit-button" type="button" value="Go" />

      <fieldset>
        <input name="lat" type="text" value="">
        <input name="lng" type="text" value="">
        <input name="query" type="hidden" value="true">
      </fieldset>
    </form>


来源:https://stackoverflow.com/questions/15697140/form-submit-with-geocomplete-jquery-geocoding-doesnt-post-latitude-longitude

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!