ajax post not working without alert message

时光怂恿深爱的人放手 提交于 2020-01-05 04:09:09

问题


i have a problem with ajax post function. Ajax function doesn't working without alert message. If add alert message, div content will be refresh and working my code.

I have a mv3 application. And post form data to this javascript function. Like that:

    function Add_Definition() {
        var data = $.extend({ call: "Add_Definition", url: "/Definition/Definition", type: "post", dataType: "html", data: $("#definition_form").serialize() }, data);
        Load(ajaxrequest(data));
    }


    function Load(val) {
        if (val == true) {
            var data = $.extend({ call: "Load", render: $("#render"), url: '@Url.Action("Definition", "Definition")', type: "get", dataType: "html", data: { "groupid": '@Request.QueryString["groupid"].ToString()'} }, data);
            ajaxrequest(data);
        }
    }

My ajax javascript function is below.

function ajaxrequest(param) { var result = true;

//alert("hi there");

$.ajax({
        type: param.type,
        url: param.url,
        data: param.data,
        dataType: param.dataType,
        success: function (result) {
             $(param.render).empty();
                $(param.render).html(result);
            result = true;
        },
        error: function (request, status, error) {
           result= false;
        }
    });
return result; }

If remove // char from javascript code, it will not work, (need refresh page), if have a alert message, content will be refresh with load function.

How is error?


回答1:


you can also direct call like

var divElem = $('#yourdivid').load('@Url.Action("Definition", "Definition")');


来源:https://stackoverflow.com/questions/23810813/ajax-post-not-working-without-alert-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!