【发布时间】:2018-11-11 00:36:59
【问题描述】:
我的表单应该使用 AJAX 发布,我拥有的所有其他设备都可以发布,除了 android。我试过改变获取方法。我什至有条件查找设备是否是 android,但我希望能够向 android 用户提供 AJAX。如果我需要提供更多信息,如果有人处理过类似的事情,我也会非常高兴。
html:
<form method='post' action='insert.php' id="requestForm">
<input class="ifields" type="text" id="song_name" name="song_title" placeholder="Song">
<input class="ifields" type="text" id="song_author" name="song_artist" placeholder="Artist">
<input class="ifields" type="text" id="song_singer" name="users_name" placeholder="Your Name">
<br><br><button type="button" name="btn_add" id="btn_add" class="btn btn-xs btn-success isubmit">Submit</button>
</form>
jquery:
$(document).on('click', '#btn_add', function(e){
var song_name = $('#song_name').val();
var artist_name = $('#song_author').val();
var user_input_name = $('#song_singer').val();
if(song_name == '')
{
alert("Enter song Name");
return false;
}
if(artist_name == '')
{
alert("Enter artist Name");
return false;
}
if(user_input_name == '')
{
alert("Enter your name Name");
return false;
}
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
$.ajax({
url:"insert_admin.php",
method:"POST",
data:{song_name:song_name, artist_name:artist_name, user_input_name:user_input_name},
dataType:"text",
success:function(data)
{
alert("your song was added");
fetch_data();
$("form")[0].reset();
}
})
}
else{
e.preventDefault();
$.ajax({
url:"insert_admin.php",
method:"POST",
data:{song_name:song_name, artist_name:artist_name, user_input_name:user_input_name},
dataType:"text",
success:function(data)
{
alert("your song was added");
fetch_data();
$("form")[0].reset();
}
})
}
});
【问题讨论】:
-
你是如何以及何时调用 ajax 函数的。
-
@MohammadC 我刚刚更新了脚本
-
谢谢。试试我的解决方案,让我知道结果如何。