Jquery - Submit Form To Restful Url May 30, 2024 Post a Comment My mind has gone 100% blank on this so need some guidance please. Solution 1: Solution with jquery:$('#searchForm').on('submit', function(event){ $('[name=s]').prop('disabled', true) $(this).attr('action', 'http://example.com/rest/ful/url/' + $('[name=s]').val()); }); Copyhttps://jsfiddle.net/3y4efht0/1/Solution 2: Use .submit event of jquery and fetch the input value and use window.location.href to achieve your requirement. Please check below snippet.Baca JugaJquery - Looping A .load() Inside A 'for' StatementPostman Put Json Returns NullWhat Is The Best Way To Update All Clients When Flask Database Changes Without Polling?$("#searchForm").submit(function( event ) { var searchTerm = $("input[name='s']").val(); if($.trim(searchTerm)!=""){ var redirectURL = "http://example.com/rest/ful/url/"+$.trim(searchTerm)+"/"; console.log(redirectURL); window.location.href=redirectURL; }else{ alert("Please enter search term!"); } });Copy<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formaction="/"id="searchForm"><inputtype="text"name="s"placeholder="Search..."><inputtype="submit"value="Search"></form>CopySolution 3: You don't need jquery to do that, but it can help, you have to listen for the submit event, prevent the default behaviour and redirect to the page you want : $('#searchForm').on('submit', function(e){ e.preventDefault(); document.location.href = 'http://example.com/rest/ful/url/'+$('#s').val()+'/' }) Copy Share You may like these postsHow Can I Check If The Mouse Exited The Browser Window Using Javascript/jquery?How Can I Execute The Events In Sequence In Jquery Ajax FunctionJquery Smooth AnimationRemove Duplicates From Json Array And Combine Its Id's Using Node.js Post a Comment for "Jquery - Submit Form To Restful Url"
Post a Comment for "Jquery - Submit Form To Restful Url"