If div with class Easy
is present in the body, I want AJAX to run the url urlEasy.php
If div with class Medium
is present in the body, I want it to run urlMedium.php
Attempt Using Jquery Global Variable
<script>
var UrlReplacer = {};
$(document).ready(function() {
if ($("div").hasClass("Easy")){
UrlReplacer = "urlEasy.php";
} elseif ($("div").hasClass("Medium")){
UrlRreplacer = "urlMedium.php";
}
});
</script>
<script type='text/javascript'>
$(document).ready(function () {
$('#classadderform').on('submit', function(e) {
e.preventDefault();
$.ajax({
url : Urlreplacer ,
type: "POST",
data: $(this).serialize(),
success: function (data) {
},
});
});
});
</script>
The AJAX runs fine when I directly write the desired url as shown below, so the issue is not related to the form, the AJAX, or the linked urls. I also know with certainty that a div with class Easy
is present in the body. The issue is creating a global Jquery variable that I can then use to define the url.
<script type='text/javascript'>
$(document).ready(function () {
$('#classadderform').on('submit', function(e) {
e.preventDefault();
$.ajax({
url : "urlEasy.php",
type: "POST",
data: $(this).serialize(),
success: function (data) {
},
});
});
});
</script>