English 中文(简体)
行动主计长结束发言,但阿马齐格世界大会的成功呼吁没有被称作?
原标题:Action Controller finishes but AJAX success callback is not called?

我有一封信件,其中写明了一名智者,并将其送交我的行动主计长。 主计长回避了标语,并知道如何将其编为一种观点。

行动控制员非常简单,喜欢:

[HttpPost]
        public String SaveNumberMatrix(NumberViewModel model) {
            return "Finished";
        }

The AJAX function:

function saveNumberMatrix(object, actioncontroller) {

    var finished = false;

    $.ajax({
    url: actioncontroller,
    type:  POST ,
    data: JSON.stringify(object),
    dataType:  json ,
    processData: false,
    contentType:  application/json; charset=utf-8 ,
    success: function (data) {
        alert(data);
        finished = true;
        },   
    });
    alert(finished);
    return finished;
}

我在行动主计长上台,在把手脚(f)改为“ step”前,已经完成了警示。

"return "Finished";

The sucess callback is never called Where am i doing it wrong?

最佳回答

复兴共和与民主军的整个观点是,你只能在成功退却的范围内处理结果,这是不合时宜的意思。 <编码>$.ajax 方法开始向服务器申请,并立即返回。 在现阶段,成品的价值仍然不实,你正在离开这一功能。 不久之后,美国宇宙航空研究开发机构完成了成功的呼吁。 只有在这一反馈中,你才能利用服务器发送的结果。

在使用日本宇宙航空研究开发机构时,你不应以连续和同步的方式制定你的javascript。

因此,应该这样:

$.ajax({
    url:  /actioncontroller/savenumbermatrix ,
    type:  POST ,
    data: JSON.stringify(object),
    dataType:  json ,
    processData: false,
    contentType:  application/json; charset=utf-8 ,
    success: function (data) {
        // TODO: only here you can use the results of an AJAX call
    }
});

我也建议你让你的控制者采取行动,永远恢复行动成果,而不是表明:

[HttpPost]
public ActionResult SaveNumberMatrix(NumberViewModel model) {
    return Json("Finished");
}

您的代码的另一个问题是,你在回复中注明了<条码>数据表:json ,并从服务器中退回了一张显示<条码>Finished,该服务器是无效的。

问题回答

你不要忘记成功,因为你没有回过头来,你需要把 j子寄回你们的数据。 类型为json。 因此,它可能犯错。

From the jQuery docs:

dataTypeString
Default: Intelligent Guess (xml, json, script, or html)
The type of data that you re expecting back from the server. 

在您的情形下,请具体说明json,但显然不送回json

It s seems like your ajax request does not reach to the server. please use ajax error function.

error: function(a,b,c){alert(a+b+c)}

并找出问题

添加作为虚伪的同义参数(如:假的)之后,美国宇宙航空研究开发机构的方法将被 called笑。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签