简体   繁体   中英

jQuery Dynamic form not posting on mobile

I am trying to create a form dynamically and then submitting it. I have it working on desktop browsers but on mobile Android and iOS, it does not work.

What it is doing is refreshing the page and not sending the post request.

Here is the code:

var $form = $(document.createElement('form')).attr('action', '/results').attr('method', 'POST');
$form.append(form.find('input[name="_token"]'));
$form.append('<input type="hidden" name="term" value="'+term+'">');
$form.append('<input type="hidden" name="extra" value="'+extra+'">');
$form.append('<input type="hidden" name="value" value="'+value+'">');
$form.append('<button id="submitSearch" type="submit"></button>');
$($form).appendTo(document.body);
$($form).submit();

Any ideas on why it would not work on mobile browsers?

There seemed to be an issue with Laravel not seeing the token correctly.

I created the form in the page and set the fields in the JS. This then seemed to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM