Javascript + Ajax is not returning as expected

Question:

I'm trying to send this page's data to the server, but Js doesn't return the Message variable…

Link

I know little about JS and would like to know how to call the variable as soon as the server receives the data.

Answer:

Enable server-side CORS… ( http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api )

If you add an error to your ajax, you'll notice it lands there.

$.ajax({
    type: "GET",
    url:  strUrl,
    crossDomain: true,
    dataType: 'jsonp',
    beforeSend: function (xhr) {
       xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
    },
    success: function(data)
    {
        if (data == "Realizado com sucesso.")
        {
            var Mensagem = "Obrigado por se cadastrar na BILLABONG!";

            $("#divNewsLetterContainer").html("");
            $("#divNewsLetterContainer").append("<span class='spnMensagemNewletter'>" + Mensagem + "</span>");
        }
        else
        {
            alert(data);
        }
    },
    error: function(data) {
        alert('Ocorreu um erro, olhe o console');
        console.log(data);
    }
});

Add an action to your form:

   <form action="javascript:void(0);" id="divNewsLetterContainer" class="newsletter" onsubmit="EnviarNewsLetter();">
        <input type="text" class="fitext" name="nome" id="nome" size="20" value="" placeholder="name" required="">
        <input type="email" name="email" id="email" size="20" value="" placeholder="name@email.com" required="">
        <input type="submit" id="btw-ok" value="assinar" class="btw-ok">
   </form>
Scroll to Top