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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题