shadd Posted August 23 Share Posted August 23 i have this php script: $result='Osucess' echo $result; i have this jquery ajax: $("#add_sub").submit(function (e) { e.preventDefault(); var formDatax = new FormData($('#add_sub')[0]); $.ajax({ type: "POST", url: 'answers.php', data: formDatax, //Options to tell jQuery not to process data or worry about content-type. cache: false, contentType: false, processData: false, success: function(data){ if(data.charAt(0) ==="O"){ alert(data); }else{ alert("failed"); } } }); }); but it does not work at all.what is the problem?? Quote Link to comment https://forums.phpfreaks.com/topic/323295-how-to-get-first-letter-of-a-string-in-ajax-response/ Share on other sites More sharing options...
Barand Posted August 23 Share Posted August 23 I'd start by checking what data contains with console.log(data) Quote Link to comment https://forums.phpfreaks.com/topic/323295-how-to-get-first-letter-of-a-string-in-ajax-response/#findComment-1633409 Share on other sites More sharing options...
shadd Posted August 24 Author Share Posted August 24 (edited) 7 hours ago, Barand said: I'd start by checking what data contains with sole.log(data) it contains "Osucess" but the if tatements do not work out And when i try console.log(data[0]); it shows nothing at all. Edited August 24 by shadd clarity Quote Link to comment https://forums.phpfreaks.com/topic/323295-how-to-get-first-letter-of-a-string-in-ajax-response/#findComment-1633418 Share on other sites More sharing options...
Solution shadd Posted August 24 Author Solution Share Posted August 24 this is what i did to get it var str= data ; let removedSpacesText = str.split(" ").join(""); alert(removedSpacesText); alert(removedSpacesText[0]); and it worked Quote Link to comment https://forums.phpfreaks.com/topic/323295-how-to-get-first-letter-of-a-string-in-ajax-response/#findComment-1633504 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.