jquery - How to submit a same form with different url? -
in click of button form submit , success data contains next_url. goal submit same form next_url. possible.? sorry if question asked give me url.
my script code:
$(document).ready(function(){ $('form').submit(function(event){ event.preventdefault(); $.ajax({ type: 'post', url: '/', async: false, data: $("#form_to_submit").serialize(), success: function(data){ console.log(data); $('form').attr('action', data.next_url); $('form').unbind('submit').submit(); } }) return false; }) })
and sample django view here.
def home(request): data_dict = {} if request.method == 'post': form_data = request.post['data'] data_dict['form_data'] = form_data data_dict['next_url'] = reverse('frontend:first_term') return jsonresponse(data_dict) return render(request, 'index.html', {'data_list': data_list}) def first_term(request): data_dict = {} data_dict['next_url'] = reverse('frontend:second_term') return jsonresponse(data_dict)
update 1 :
above code redirect localhost.com/first_term
, {"next_url": "/second_term"}
context.
but expected first_term post value , next_url in success method [ third_term
]
you can try one:
$(document).ready(function() { $('form').submit(function(event) { event.preventdefault(); $.ajax({ type: 'post', url: '/', async: false, data: $("#form_to_submit").serialize(), datatype: 'json', cache: false success: function(data) { console.log(data); $('form').attr('action', data.next_url); $('form').unbind('submit').submit(); } }) }) })
or
Comments
Post a Comment