AJAX POST method isn't working in android









up vote
0
down vote

favorite
1












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();

)

);









share|improve this question



















  • 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














up vote
0
down vote

favorite
1












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();

)

);









share|improve this question



















  • 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












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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();

)

);









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












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.






share|improve this answer


















  • 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











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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.






share|improve this answer


















  • 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















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.






share|improve this answer


















  • 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













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.






share|improve this answer














$("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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 16:09

























answered Nov 11 at 15:34









Mohammad C

1,1131212




1,1131212







  • 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




    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


















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto