AJAX POST method isn't working in android
up vote
0
down vote
favorite
My form should post with AJAX and every other device I have is able to post besides android. I've tried changing the method to get. I even have a conditional to find if the device is an android but i'd like to be able to offer the AJAX to android users. If i need to offer more information i'm more than happy too if anyone has dealt with anything similar.
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();
}
})
}
});
jquery ajax forms post
add a comment |
up vote
0
down vote
favorite
My form should post with AJAX and every other device I have is able to post besides android. I've tried changing the method to get. I even have a conditional to find if the device is an android but i'd like to be able to offer the AJAX to android users. If i need to offer more information i'm more than happy too if anyone has dealt with anything similar.
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();
}
})
}
});
jquery ajax forms post
1
How and when are u calling the ajax function.
– Mohammad C
Nov 11 at 0:39
@MohammadC I just updated the script
– Ari Patwary
Nov 11 at 2:51
Thanks. Try my solution and let me know how it goes.
– Mohammad C
Nov 11 at 20:34
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My form should post with AJAX and every other device I have is able to post besides android. I've tried changing the method to get. I even have a conditional to find if the device is an android but i'd like to be able to offer the AJAX to android users. If i need to offer more information i'm more than happy too if anyone has dealt with anything similar.
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();
}
})
}
});
jquery ajax forms post
My form should post with AJAX and every other device I have is able to post besides android. I've tried changing the method to get. I even have a conditional to find if the device is an android but i'd like to be able to offer the AJAX to android users. If i need to offer more information i'm more than happy too if anyone has dealt with anything similar.
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();
}
})
}
});
jquery ajax forms post
jquery ajax forms post
edited Nov 11 at 2:50
asked Nov 11 at 0:36
Ari Patwary
386
386
1
How and when are u calling the ajax function.
– Mohammad C
Nov 11 at 0:39
@MohammadC I just updated the script
– Ari Patwary
Nov 11 at 2:51
Thanks. Try my solution and let me know how it goes.
– Mohammad C
Nov 11 at 20:34
add a comment |
1
How and when are u calling the ajax function.
– Mohammad C
Nov 11 at 0:39
@MohammadC I just updated the script
– Ari Patwary
Nov 11 at 2:51
Thanks. Try my solution and let me know how it goes.
– Mohammad C
Nov 11 at 20:34
1
1
How and when are u calling the ajax function.
– Mohammad C
Nov 11 at 0:39
How and when are u calling the ajax function.
– Mohammad C
Nov 11 at 0:39
@MohammadC I just updated the script
– Ari Patwary
Nov 11 at 2:51
@MohammadC I just updated the script
– Ari Patwary
Nov 11 at 2:51
Thanks. Try my solution and let me know how it goes.
– Mohammad C
Nov 11 at 20:34
Thanks. Try my solution and let me know how it goes.
– Mohammad C
Nov 11 at 20:34
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
$("btn_add").click(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;
}
$.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();
$("#requestForm").reset();
}
});
});
Hey, Man. try this, let me know if it works. This should hopefully create a click event listener on the button only. Try on pc first and check console log for any errors. If there are no errors. Then proceed to trying it on android phone. Fingers crossed, there are no issues.
1
Thank you man! i ran it through several androids and its working on my application. I would of never gotten the quotations. Do you know why i have to have the states in quotes in certain scenarios and others not? @MohammadC
– Ari Patwary
Nov 13 at 4:57
You need to quotes to name the field which needs to be a string. Currently you were naming the field dynamically and also setting the data dynamically, the latter is fine. If you set the name of the field dynamically how will you know what the field name is. For example someone typed test as song name. You are sending {"test":"test"}. You want to send {"song_name":"test"} so that you can get the song name by referring to song_name i hope that makes sense. I am also baffled as to why it worked in some cases and not others especially android. Maybe PC browsers work a little differently.
– Mohammad C
Nov 13 at 12:08
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
$("btn_add").click(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;
}
$.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();
$("#requestForm").reset();
}
});
});
Hey, Man. try this, let me know if it works. This should hopefully create a click event listener on the button only. Try on pc first and check console log for any errors. If there are no errors. Then proceed to trying it on android phone. Fingers crossed, there are no issues.
1
Thank you man! i ran it through several androids and its working on my application. I would of never gotten the quotations. Do you know why i have to have the states in quotes in certain scenarios and others not? @MohammadC
– Ari Patwary
Nov 13 at 4:57
You need to quotes to name the field which needs to be a string. Currently you were naming the field dynamically and also setting the data dynamically, the latter is fine. If you set the name of the field dynamically how will you know what the field name is. For example someone typed test as song name. You are sending {"test":"test"}. You want to send {"song_name":"test"} so that you can get the song name by referring to song_name i hope that makes sense. I am also baffled as to why it worked in some cases and not others especially android. Maybe PC browsers work a little differently.
– Mohammad C
Nov 13 at 12:08
add a comment |
up vote
1
down vote
accepted
$("btn_add").click(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;
}
$.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();
$("#requestForm").reset();
}
});
});
Hey, Man. try this, let me know if it works. This should hopefully create a click event listener on the button only. Try on pc first and check console log for any errors. If there are no errors. Then proceed to trying it on android phone. Fingers crossed, there are no issues.
1
Thank you man! i ran it through several androids and its working on my application. I would of never gotten the quotations. Do you know why i have to have the states in quotes in certain scenarios and others not? @MohammadC
– Ari Patwary
Nov 13 at 4:57
You need to quotes to name the field which needs to be a string. Currently you were naming the field dynamically and also setting the data dynamically, the latter is fine. If you set the name of the field dynamically how will you know what the field name is. For example someone typed test as song name. You are sending {"test":"test"}. You want to send {"song_name":"test"} so that you can get the song name by referring to song_name i hope that makes sense. I am also baffled as to why it worked in some cases and not others especially android. Maybe PC browsers work a little differently.
– Mohammad C
Nov 13 at 12:08
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
$("btn_add").click(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;
}
$.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();
$("#requestForm").reset();
}
});
});
Hey, Man. try this, let me know if it works. This should hopefully create a click event listener on the button only. Try on pc first and check console log for any errors. If there are no errors. Then proceed to trying it on android phone. Fingers crossed, there are no issues.
$("btn_add").click(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;
}
$.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();
$("#requestForm").reset();
}
});
});
Hey, Man. try this, let me know if it works. This should hopefully create a click event listener on the button only. Try on pc first and check console log for any errors. If there are no errors. Then proceed to trying it on android phone. Fingers crossed, there are no issues.
edited Nov 11 at 16:09
answered Nov 11 at 15:34
Mohammad C
1,0881212
1,0881212
1
Thank you man! i ran it through several androids and its working on my application. I would of never gotten the quotations. Do you know why i have to have the states in quotes in certain scenarios and others not? @MohammadC
– Ari Patwary
Nov 13 at 4:57
You need to quotes to name the field which needs to be a string. Currently you were naming the field dynamically and also setting the data dynamically, the latter is fine. If you set the name of the field dynamically how will you know what the field name is. For example someone typed test as song name. You are sending {"test":"test"}. You want to send {"song_name":"test"} so that you can get the song name by referring to song_name i hope that makes sense. I am also baffled as to why it worked in some cases and not others especially android. Maybe PC browsers work a little differently.
– Mohammad C
Nov 13 at 12:08
add a comment |
1
Thank you man! i ran it through several androids and its working on my application. I would of never gotten the quotations. Do you know why i have to have the states in quotes in certain scenarios and others not? @MohammadC
– Ari Patwary
Nov 13 at 4:57
You need to quotes to name the field which needs to be a string. Currently you were naming the field dynamically and also setting the data dynamically, the latter is fine. If you set the name of the field dynamically how will you know what the field name is. For example someone typed test as song name. You are sending {"test":"test"}. You want to send {"song_name":"test"} so that you can get the song name by referring to song_name i hope that makes sense. I am also baffled as to why it worked in some cases and not others especially android. Maybe PC browsers work a little differently.
– Mohammad C
Nov 13 at 12:08
1
1
Thank you man! i ran it through several androids and its working on my application. I would of never gotten the quotations. Do you know why i have to have the states in quotes in certain scenarios and others not? @MohammadC
– Ari Patwary
Nov 13 at 4:57
Thank you man! i ran it through several androids and its working on my application. I would of never gotten the quotations. Do you know why i have to have the states in quotes in certain scenarios and others not? @MohammadC
– Ari Patwary
Nov 13 at 4:57
You need to quotes to name the field which needs to be a string. Currently you were naming the field dynamically and also setting the data dynamically, the latter is fine. If you set the name of the field dynamically how will you know what the field name is. For example someone typed test as song name. You are sending {"test":"test"}. You want to send {"song_name":"test"} so that you can get the song name by referring to song_name i hope that makes sense. I am also baffled as to why it worked in some cases and not others especially android. Maybe PC browsers work a little differently.
– Mohammad C
Nov 13 at 12:08
You need to quotes to name the field which needs to be a string. Currently you were naming the field dynamically and also setting the data dynamically, the latter is fine. If you set the name of the field dynamically how will you know what the field name is. For example someone typed test as song name. You are sending {"test":"test"}. You want to send {"song_name":"test"} so that you can get the song name by referring to song_name i hope that makes sense. I am also baffled as to why it worked in some cases and not others especially android. Maybe PC browsers work a little differently.
– Mohammad C
Nov 13 at 12:08
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244796%2fajax-post-method-isnt-working-in-android%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
How and when are u calling the ajax function.
– Mohammad C
Nov 11 at 0:39
@MohammadC I just updated the script
– Ari Patwary
Nov 11 at 2:51
Thanks. Try my solution and let me know how it goes.
– Mohammad C
Nov 11 at 20:34