我是jquery/ajax的新手,我遇到了簡單提交的問題。Jquery Ajax自動刷新頁面
我有一個簡單的聯繫表單(發佈)與表單上的名稱,電子郵件地址和請求。我調用了一個更新sql server數據庫表的ajax進程。當它返回成功時,我想顯示一條消息,說您的請求已發送。但每次成功返回時頁面都會刷新。
這裏是我的代碼
<script type="text/javascript" src="assets/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript" src="assets/plugins/jquery/jquery-migrate.min.js"></script>
<script type="text/javascript" src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
<!-- JS Implementing Plugins -->
<script type="text/javascript" src="assets/plugins/back-to-top.js"></script>
<script type="text/javascript" src="assets/plugins/flexslider/jquery.flexslider-min.js"></script>
<script type="text/javascript" src="assets/plugins/layer-slider/layerslider/js/greensock.js"></script>
<script type="text/javascript" src="assets/plugins/layer-slider/layerslider/js/layerslider.transitions.js"></script>
<script type="text/javascript" src="assets/plugins/layer-slider/layerslider/js/layerslider.kreaturamedia.jquery.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="assets/plugins/gmap/gmap.js"></script>
<script type="text/javascript" src="assets/plugins/sky-forms/version-2.0.1/js/jquery.validate.min.js"></script>
<!-- JS Customization -->
<script type="text/javascript" src="assets/js/custom.js"></script>
<!-- JS Page Level -->
<script type="text/javascript" src="assets/js/app.js"></script>
<script type="text/javascript" src="assets/js/plugins/layer-slider.js"></script>
<script type="text/javascript" src="assets/js/pages/BusyIndicator.js"></script>
<script type="text/javascript">
jQuery(document).ready(function ($) {
App.init();
App.initSliders();
renderc27slider();
renderpage();
LayerSlider.initLayerSlider();
$("#btnSendRequest").click(function (data) {
$("#div-validation-error").hide();
$("#div-process-success").hide();
var valid = $('#validation-form').valid();
if (valid == false) {
$('#div-validation-error').show();
} else {
ajaxindicatorstart("sending the request...please wait");
var vname = $("#txtname").val();
var vemailaddress = $("#txtemailaddress").val();
var vrequest = $("#txtrequest").val();
var jsonData = { name: vname, emailaddress: vemailaddress, request: vrequest };
$.ajax({
type: "POST",
url: "Process.asmx/TryRVWEBRequest",
data: JSON.Stringify(jsonData),
datatype: "json",
success: function (data) {
if (data.d == "OK") {
alert("in Success=true");
$("#div-process-success").show();
} else {
alert("in Success=false");
$("#div-process-success").show();
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
};
});
$('#validation-form').validate({
rules: {
txtname: {
required: true
},
txtemailaddress: {
required: true,
email: true
},
txtrequest: {
required: true
}
},
messages: {
txtname: {
required: "Please provide a name.",
},
txtemailaddress: {
required: "Please provide an email address",
email: "Please provide a valid email address"
}
}
});
});
</script>
這真是難倒我,所以任何幫助,將不勝感激
爲什麼在您的JavaScript代碼中有
標籤? – tabz100
您的代碼中也沒有jQuery庫 –
我試圖在Stackoverflow中正確格式化並顯示標籤。他們不在代碼中。 – Tim