What url format do you recommend for use in AJAX / jQuery?

0

I have functions like the insertion of data in the DB that I do through AJAX, my problem is that when I put the url, I put it with www and http, it works in chrome and in Firefox, but not in IE nor Opera. What is this due to?

Here I leave the AJAX code:

$("input[name='enviar_login']").click(function(){
        var datos = $(".formulario_login").serialize();
        $.ajax({
            method:"POST",
            url:"http://ejem.com/login/login.php",
            data:datos,
            success:function(result){
                if (result=="") {
                    $(".login p").css({
                        "background":"rgba(255,0,0,.2)",
                        "border-radius":"10px 10px 0 0"
                    });
                }else if(result!=""){
                    $(location).attr("href","http://ejem.com/login/" + result);
                }
            }
        });
        return false;
});

Works in Firefox and Chrome but not in IE or Opera

Thank you.

    
asked by cat_12 17.12.2018 в 11:41
source

1 answer

0

Hello the solution is this:

        $("input[name='enviar_login']").click(function(){
        <?php $root = $_SERVER['DOCUMENT_ROOT']; ?>
        var datos = $(".formulario_login").serialize();
        $.ajax({
            method:"POST",
            url:"<?php echo $root; ?>/login/login.php",
            data:datos,
            success:function(result){
                if (result=="") {
                    $(".login p").css({
                        "background":"rgba(255,0,0,.2)",
                        "border-radius":"10px 10px 0 0"
                    });
                }else if(result!=""){
                    window.location.assign("<?php echo $root; ?>/login/" + result);
                }
            }
        });
        return false;
    });

What I do is that the php variable, the step to javascript, and whose varaible takes the root path of my web.

    
answered by 17.12.2018 / 16:12
source