-1

Trying to send a simple Jquery GET request, which doesn't work.

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>
            $(document).ready(function() {
                $("#clk").click(function() {
                    $.get('http://www.abelski.com/courses/ajax/emailajaxservice.php', { email: 'mymail@example.com'}, function() {
                        alert("Sent");
                    });
                });
            });
        </script>
    </head>
    <body>
            <input type="text" id="email" />
            <input type="button" id="clk" />
            <span id="res"></span>
    </body>
</html>

I don't get any alert. what is the problem in my code?

mcuadros
  • 4,098
  • 3
  • 37
  • 44
Billie
  • 8,938
  • 12
  • 37
  • 67
  • 1
    Check the browser logs and see if the request comes back with an error. – heymega Dec 06 '13 at 13:23
  • See demo here with example http://www.thecodedeveloper.com/jquery-ajax-select-values-filled-dynamically – thecodedeveloper.com Dec 06 '13 at 13:24
  • 1
    Are you working on this domain http://www.abelski.com/. If not you may have cross origin server issues. Refer http://stackoverflow.com/questions/2067029/getting-around-same-origin-policy-in-javascript-without-server-side-scripts – gimg1 Dec 06 '13 at 13:29
  • There is nothing wrong in your code , if your browser is `chrome` and you are not working on `abelski.com/` then you can see this error `No 'Access-Control-Allow-Origin' header is present on the requested resource. ` – Bharath R Dec 06 '13 at 13:31
  • I think you are trying make an inter-domain call .. is www.abelski.com a different domain .. if that is the case you will have to explicitly edit the header .. or in that domain [www.abelski.com] you will have to allow your ajax call from your domain from which it is called. – A J Dec 06 '13 at 14:17

2 Answers2

0

In your code snippet, the function

function() { alert("Sent"); }

will be called when the request succeeds. If it fails for any reason (cross-domain requests are forbidden, answer returns with a non OK code, ...) nothing will be executed.

You can add a .fail() listener to see if an error was triggered :

$.get( ... ).fail(function(){ alert("Error"); });

Check your web console to have more detail on the failure.

LeGEC
  • 46,477
  • 5
  • 57
  • 104
0

Why don't you try this one:

           $.ajax({
                type: "GET",
                url: RequestURL,
                dataType: "html",
                success: function(htm) {
                   alert(htm);
                    }
                }
            });
Irfan TahirKheli
  • 3,652
  • 1
  • 22
  • 36