<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h1>Ajax Method in Jquery</h1>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivzH9V1GHFkK0q0bNtjJguqmg7i1bgxDsQWSCI9cnYgxNE7dA0bZvBWbqlA_dzq3nMzmWXOvoqdRA1U4Hg4pJHeN2PZAqEeWfX_tsXGN-03XK_CRONhL-dy46GIhewvLgeD2l0PhsYb8Mm/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> $(document).ready(function() {
$("#from_station1").change(function(){ var city_id = $(this).val();
$.ajax({
method: "POST",
url: "get_to_station.php?city_id=" + city_id,
success:function(data)
{
$("#settostation").html(data); // data setting on particular id
});
});
});
</code></pre>
// Ajax with success redirection with file upload
$(function () {
$("#testfrm").validate({
rules: {
name: {
required: true
},
address: {
required: true,
maxlength: 100
},
file: {
required: true
}
},
messages: {
name: {
required: "Please select name."
},
address: {
required: "Please enter address.",
maxlength: 'Address length should not be more than 100.'
},
file: {
required: "Please select file."
}
},
submitHandler: function (response) {
var formData = new FormData($('#testfrm')[0]);
$.ajax({
url: set_your_url,
type: 'POST',
data: formData,
dataType: 'json',
contentType: false,
processData: false,
beforeSend: function () {
// Start loading
},
complete: function () {
//Stop loading
},
success: function (response) {
switch (response.status) {
case 1:
showalert(response.msg, 'testfrm', 'alert-danger');
$('form[name="testfrm"]').trigger("reset");
break;
case 0:
showalert(response.msg, 'testfrm', 'alert-success');
window.location = 'redirection location';
break;
default:
break;
}
}
});
}
});
});
</div>
Comments
Post a Comment