weixin_33694172 2016-07-13 22:00 采纳率: 0%
浏览 30

JS中的AJAX无法正常工作

i am trying to use ajax in one of JavaScripts to send an email form WebSite. But it is not working. I simplified ajax code as much as i can but still it is not working it is like web is totally ignoring this ajax script.

JS/JQuery code

    <script>
        function sendMail() {
            $.ajax({
                url: 'http://us13.api.mailchimp.com/3.0/',
                success: function (response) {
                    alert(response);
                }
            });
        };
   </script>

and Html code is classic button:

 <button type="submit" onclick="sendMail()">Use AJAX</button>

Is there something wrong?

EDIT I tried both ways as u said (change type to button and also with prevent to submit) but still same problem now code looks like this:

<button type="button" onclick="sendMail()">Use AJAX</button>


<script>

    function sendMail() {
        alert("test");
        $.ajax({
            url: 'http://us13.api.mailchimp.com/3.0/',
            success: function (response) {
                alert(response);
            }
        });
    }

alert("test") is executed properly but ajax is still ignored

  • 写回答

0条回答 默认 最新

    报告相同问题?