javascript - Form submition using AJAX is not working -
im tring submit form other page using ajax, doesn't send post.
javascript on top of page.
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script> $(function(){ $(".button").click(function(){ event.preventdefault(); var name = $("#name").val(); var datavar = "name=" + name; $.ajax({ type: "post", url: "https://www.example.ee/index.php?e=area_sa&date=2010", data: datavar, success: function() { alert("works"); } }); }); }); <script> and html code:
<form> <input type="text" name="name" id="name"> <input type="submit" name="submit" class="button" value="add"> </form>
it's not working because you're trying make cross-domain ajax request.
if have domain mywebsite.com, ajax requests should limited domain, e.g. mywebsite.com/example/ajax/request.
what you're trying (cross-domain request) possible involves workaround that's bit more complicated, , makes use of different library calls.
Comments
Post a Comment