.ajax()有时是有效的,有时则不然 [英] .ajax() sometimes works and sometimes doesn't

查看:72
本文介绍了.ajax()有时是有效的,有时则不然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计我面临着一个有趣的问题。我有2个文件:ShowRecord.aspx和Ekle.aspx。在Ekle.aspx我有一个像http://prntscr.com/8tl55z [ ^ ]



在ShowRecord.aspx中我有一个gridview,我可以在数据库中打印我的值。



http://prntscr.com/8tl5kk [ ^ ]



当用户按下ShowRecord.aspx上的Ekle按钮时,我将Ekle.aspx加载到div中(div中的标签,你可以从上面的链接看到)。



我想要的是,当用户填写表格并按下提交按钮时,我想要立即显示更改。首先,我发送一个.ajax()帖子将记录保存到数据库,再次执行.ajax()帖子将值打印到屏幕上。



代码alw ays将记录保存到数据库。但并不总是立即显示更改。有时显示,有时不显示。我不知道是什么问题?请你点赞我吗?

Guys I'm facing with an interesting problem.I have 2 file: ShowRecord.aspx and Ekle.aspx .In Ekle.aspx I have a web form like the pic http://prntscr.com/8tl55z[^]

And In ShowRecord.aspx I have a gridview which I can print values my in database.

http://prntscr.com/8tl5kk[^]

When user press 'Ekle' button on ShowRecord.aspx, I load Ekle.aspx into the div(a label inside the div,you can see from the upper link).

What I want is,when user fill the form and press the submit button,I want to show the changes immediately.To do this first I send a .ajax() post to save record to database,And again do a .ajax() post to print values to screen.

Code always save records to database.But is NOT always show the changes immediately.Sometimes shows and sometimes do not.I don't know what is the problem?Can you enlight me please?

推荐答案

Quote:

代码总是将记录保存到数据库。

Code always saves the records to the database.

这意味着ajax的代码工作正常,当它将数据发送到其他页面(或ajax提交数据的任何地方)时,问题就出现了响应未显示。



问题,您在Web开发中遇到的任何问题始终都会记录在控制台中。按 F12 以获取开发人员工具中的控制台,并查看该事件是否已记录在那里。也许,在大多数情况下,你不会发回任何东西,if ... else可能会改变程序的逻辑或路径。



无论如何,检查控制台可能有每个事件的原因。其次,在网络选项卡中,查看您的请求的日志。显示每个请求及其状态代码,查看从服务器发送的响应(如果有的话!)。这可以帮助您将问题解决为您可以解决的单个逻辑错误。

Which means that the code for ajax is working fine, as it sends the data to other page (or wherever ajax is submitting the data) then the problem comes is that response is not shown.

The problem, any problem that you may encounter in web development is always logged in the console. Press F12 to get the console in developer tools, and see if that event is logged there. Perhaps, in most cases you are not sending anything back, an if...else may change the logic or path of the program.

Anyways, check the console there may be a reason for each and every event. Secondly, in the networking tab, see for the logs of your requests. Each request, along with their status code is shown, see what response was sent from server (if any!). This would help you to bring down the problem into one single logical error that you can solve.


您需要为任何人发布一些代码以更好地帮助您。无论如何,通过阅读你的帖子,听起来像代码向服务器发出两个请求,有时保存记录首先到达那里,有时打印请求首先到达(这就是为什么它是空白的)。不清楚您的代码当前是什么样的或jQuery的版本,但您可以尝试更新代码以确保在发出第二个请求之前完成第一个请求。



提示:根据jQuery版本,将第二个请求包装在 .done()函数中。





jQuery.ajax()| jQuery API文档 [ ^ ]
You need to post some code for anyone to better assist you. Anyway, by reading at your post, sound like the code is firing two request to the server, sometime the save record get there first and sometime the print request reach first (that why it blank). Not clear how your code currently look like or version of jQuery, but you can try to update the code to make sure the first request is completed before firing the second request.

Hint: depending on the jQuery version, wrap the second request in the .done() function.


jQuery.ajax() | jQuery API Documentation[^]


这篇关于.ajax()有时是有效的,有时则不然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆