Created
March 16, 2018 19:53
-
-
Save anonymous/350770445e3ead80e72e08cc2108f5ce to your computer and use it in GitHub Desktop.
jQuery AJAX (source: http://jsfiddle.net/QZ3ff/3460/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body{ | |
font-family: 'Open Sans', 'Helvetica Neue', 'Arial', sans-serif; | |
font-size: 13px; | |
} | |
form span{ | |
display: block; | |
margin: 10px; | |
} | |
label{ | |
display: inline-block; | |
width: 100px; | |
} | |
input[type="text"]{ | |
border: 1px soild #ccc; | |
width: 200px; | |
padding: 5px; | |
} | |
input[type="submit"]{ | |
padding: 5px 15px; | |
} | |
span#result{ | |
padding: 5px; | |
background: #ff9; | |
} | |
img#loadingimg{ | |
display: none; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="post" action="/echo/html/" ajax="true"> | |
<span id="result"><a href="http://wp.me/p2O9K2-b">jQuery + AJAX form submit script.</a></span> | |
<span> | |
<label>Message: </label> | |
<input type="text" name="html" placeholder="Howdy..." /> | |
</span> | |
<span> | |
<label><img id="loadingimg" src="http://dev.cloudcell.co.uk/bin/loading.gif"/> </label> | |
<input type="submit" value="Submit" /> | |
</span> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function(e) { | |
$("form[ajax=true]").submit(function(e) { | |
e.preventDefault(); | |
var form_data = $(this).serialize(); | |
var form_url = $(this).attr("action"); | |
var form_method = $(this).attr("method").toUpperCase(); | |
console.log(form_data); | |
console.log(form_url); | |
console.log(form_method); | |
$("#loadingimg").show(); | |
$.ajax({ | |
url: form_url, | |
type: form_method, | |
data: form_data, | |
cache: false, | |
success: function(returnhtml){ console.log(returnhtml); | |
$("#result").html(returnhtml); | |
$("#loadingimg").hide(); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment