使用XMLHttpRequest和jQuery AJAX实现级联下拉列表时出错 [英] Error with Using XMLHttpRequest and jQuery AJAX to implement a cascading dropdown

查看:85
本文介绍了使用XMLHttpRequest和jQuery AJAX实现级联下拉列表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了 AJAX for Beginners(第2部分) - 使用XMLHttpRequest和jQuery AJAX实现级联下拉列表 [ ^ ]

代码正常工作。但是如果添加一个按钮并单击,回发将导致错误。

这是由于.Net发布后下拉列表值的更改。

如何处理此错误?我需要使用这种更新菜单的方式。

I used AJAX for Beginners (Part 2) - Using XMLHttpRequest and jQuery AJAX to implement a cascading dropdown[^]
The code worked properly. But if add a button and click, postback will cause error.
It is due to change in drop down list value after that it is issued by .Net.
What to do with this error? I need to use this way of updating menu.

推荐答案

好的:我使用Asp.Net C#2008,我在页面上有下拉列表国家,州,城市,使用Javascript和xmlHttp使用webservice填充菜单,并且它正常工作。

当用户选择菜单并尝试回发数据时,它说:

无效的回发或回调参数。 ...

我搜索并发现这是由于没有asp.net通知的菜单项列表的更改。 Asp.net呈现代码并发送到客户端,然后回发帖子以避免注入,检查所有代码与原始代码,如果有什么改变引发此错误:无效的回发或回调参数,....

有人建议禁用EnableEventValidation =true为false。但不是一个好方法。

所以问题:如何通知服务器这些更改是合法的?

有人建议使用:

ClientScript.RegisterForEventValidation(ddlLanguages, 英语);

但似乎不是正确答案。

是否可以通知.net有关更改?

是否有可能禁用某些对象的部分事件验证?

你有什么建议吗?
Ok: I use Asp.Net C# 2008, where I have drop-down list on page Country , state, city, used Javascript and xmlHttp to fill menu using webservice, and it is working properly.
when user select menus and try to post back data, it says:
Invalid postback or callback argument. ...
I searched and found that this is due to change in of menu item-list without asp.net notice. Asp.net render code and send to client, then on post back to avoid injection, check all code with original ones, if something changed raise this error :Invalid postback or callback argument,....
Some suggest to disable EnableEventValidation="true" to false. But not a good way.
So question : How to inform server that these changes are legal?
Some suggest to use :
ClientScript.RegisterForEventValidation("ddlLanguages ", "English");
but it seems not the right answer.
Is it possible to inform .net about changes?
Is it possible to disable part of event validation for some objects?
Do you have any suggestion?


我试着调查问题,似乎是问题的原因是:



当页面加载时,它有一些与控件关联的值,asp.net知道它们(也许是viewstate)。现在我们更改客户端的值,然后进行回发。这将使asp.net使用它知道的旧值来验证值,并且它们将不匹配。这将使它认为正在注入一些脚本。



现在这种行为是默认的。为了避免这个问题,我们可以使用AJAX机制来更新asp.net知道的值以及客户端的值。这可以通过使用ASP.NET ajax框架来实现级联dropdows,即使用 Updatepanel



或者我们可以转换具有 xmlhttprequest 代码的页面的事件验证,即 enableEventValidation =false



现在这将打开XSS形式的潜在黑客攻击页面,但是不应该单独依赖此事件验证来避免XSS。我们需要强大的服务器端验证来检查所有用户输入。如果您的代码不使用用户发送的值,则并不总是需要事件验证。只要我们有强大的服务器端验证,就可以关闭事件验证(虽然不推荐。
I tried to look into the problem and it seems the reason for the problem is:

When the page loads it has some values associated with the controls and asp.net knows about them (viewstate perhaps). Now we change the values on client side and them make a postback. this will make the asp.net to validate the values with the old values it knows about and they will not match. This will make it think that the some script is being injected.

Now this behavior is by default. To circumvent this problem, we can either use the AJAX mechanism that will update the values that asp.net knows along with the values on client side. This can be done by using the ASP.NET ajax framework to implement the cascading dropdows i.e. using Updatepanel.

Or we can turn of the event validation for the page having the xmlhttprequest code i.e. enableEventValidation="false"

Now this will open up the page for potential hacks in form of XSS but one should not solely rely on this eventvalidation to avoid XSS anyways. We need to have strong server side validations to check all the user input. Event validation is not always necessary if you our code does not use the values sent from the user. As long as we have strong server side validations put in place the event validations can be turned off(although not recommended.


我首先感谢您对我的问题和推文的及时和关注。

现在不再使用这种方式Ajax,作为我的朋友建议,我在其中使用了jQuerry Ajax,更新Asp.net是自动完成的。但是因为我想知道做了什么以及如何完成,我会坚持认为必须有一种方法可以克服这个错误而不是通过转换页面验证。如果jQuerry这样做,我们也必须能够这样做.MS已经发布了一些代码,但那些也是服务器端我也有评论它,希望收到回复。但我保持开放给别人回复。

谢谢

aebrs@yahoo.com
I first appreciate your prompt and kind attention to my question and tweets.
Now instead of using this way Ajax, as a friend of mine suggested, I used jQuerry Ajax that inside it, updating Asp.net is done automatically. But since I like to know what and how is something done, I would insist that there must be a way to overcome this error not by turning of page validation. If jQuerry is doing it, we must be able to do it, too. MS has issued some code but those are server side too I have commented it, hope to receive reply. Yet I keep this open for others to give their reply.
Thanks
aebrs@yahoo.com


这篇关于使用XMLHttpRequest和jQuery AJAX实现级联下拉列表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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