$ .ajax调用不在循环中工作

时间:2013-09-28 07:02:34

标签: ajax jquery

是的,我有一个不能正常运行的ajax呼叫,我不知道为什么

我的ajax电话是

function insertData(icompany,iproduct,iavailability,irelatedInformation,ishortageReason,idateUpdated)
    {
        alert('here')//comes here just once but i have a loop which calls insertData function 
        $.ajax({
            url: '../includes/drugShortage.php',
            data: {
                   action:'insert' ,
                   company: '\'' + icompany +'\'',
                   product: '\'' + iproduct+'\'',
                   availability: '\'' + iavailability+'\'',
                   relatedInformation: '\'' + irelatedInformation+'\'',
                   shortageReason: '\'' + ishortageReason+'\'',
                   dateUpdated: '\'' + idateUpdated+'\''

            },
            success: function(e)
            {
                alert(e);
            },
            error:function(e)
            {
                alert(e);
            },
            type:GET
        });
    }

我不知道造成这种情况的原因。

2 个答案:

答案 0 :(得分:1)

应引用"type"属性的值。此外,无需指定jQuery ajax调用的类型。默认值为"GET"。另外,我建议您在浏览器中打开Javascript的错误报告,并检查控制台是否存在脚本错误。它会对你有所帮助。

答案 1 :(得分:0)

我会使用setTimeout定期调用函数!我希望这段代码会为你的作业提供一些暗示!

<script type="text/javascript">
    $(document).ready(function() {
        window.setTimeout(function() {
            insertData("", "", "", "", "", ""); //Pass Data Here...!!!
        }, 1000); //Call every 1 min
    });

    function insertData(icompany, iproduct, iavailability, irelatedInformation, ishortageReason, idateUpdated) {        
        $.ajax({
            type: "GET"
            url: "../includes/drugShortage.php",
            data: {
                action: "insert",
                company: icompany,
                product: iproduct,
                availability: iavailability,
                relatedInformation: irelatedInformation,
                shortageReason: ishortageReason,
                dateUpdated: idateUpdated
            },
            success: function(event) {
                //TODO
            },
            error: function(e) {
                //TODO
            }
        });
    }
</script>