두 개의 버튼 save & continue
및 save and exit
이있는 양식이 있습니다. 이 버튼에는 2 개의 id도 있습니다. 즉, 각각 save_cont
과 save_exit
입니다.아약스는 여러 번 발생합니다.
첫 번째 버튼은 정상적으로 작동하지만 두 번째 버튼을 클릭하면 첫 번째 버튼의 아약스가 실행되어 결과적으로 내 URL을 리디렉션 할 수없고 페이지가 다시로드됩니다. 버튼의
//Save and Continue
$('#save_cont').click(function() {
$.ajax({
url: 'demo_save_data',
type: 'POST',
data: $("#add_seasonal_discount").serialize(),
success: function(result) {
if (result.success > 0) {
alert("Save and Continue");
window.location.reload();
}
}
});
});
//Save and Exit
$('#save_exit').click(function() {
$.ajax({
url: 'demo_save_data',
type: 'POST',
data: $("#add_seasonal_discount").serialize(),
success: function(result) {
if (result.success > 0) {
alert("Save and Exit");
window.location = 'demo_seasonal_discount_newpage_report.php';
}
}
});
});
$("#save_cont").unbind("click");
HTML :
public function demo_save_data() {
DB::table('demo_table') ->
insert([
'invoice_type' => Input::get('invoice_type'),
'sales_channel' => Input::get('pricing_group'),
'material' => Input::get('matnr'),
'from_date' => Input::get('fromdt'),
'to_date' => Input::get('todt'),
'discount' => Input::get('discount'),
'bukrs' => Session::get('company')
]);
return array('success' => 1);
}
편집 : 내 컨트롤러 내부
<div class="form-group col-md-12 required">
<button title="Save" id="save_cont" class="scl_issave a-link btn scl-btn-clasic scl-btn-margin-v" type="button">Save & Continue</button>
<button title="Save" id="save_exit" class="scl_issave_exit a-link btn scl-btn-clasic scl-btn-margin-v" type="button">Save & Exit</button>
</div>
demo.discount.blade.php 내부
는 말에, $("#save_cont").unbind("click");
추가 . 이제 두 번째 단추 save_exit
이 제대로 작동하지만 첫 번째 단추 save_cont
이 전혀 작동하지 않습니다.
요청 된 수정 작업을 완료했습니다. – user9141607
[Ajax 중복 클릭 허용] (https://stackoverflow.com/questions/18775455/ajax-prevent-multiple-request-on-click) – rahulsm
beeing 보내기 첫 번째 아약스 요청에 대한 관찰을 잘못 느낀다. 아마도 그것은 서버 측에서 수행 한 리다이렉션 일뿐입니다. 첫 번째 클릭 이벤트가 시작되었는지 어떻게 확인합니까? –