且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将函数参数从onchange传递给JavaScript函数

更新时间:2023-02-22 15:19:30

Ajax本质是异步的.我想您想先向服务器发送AJAX请求,并在响应结果上将客户端的用户重定向到另一页.

Ajax nature is asynchronous. I guess you want to first send an AJAX request to the server, and on the result of its response, redirect user on the client side to another page.

您的代码中发生的事情是,首先,调用了 MakeRequest()函数,但该函数立即返回(因为ajax是异步的),因此,的下一部分onchange 属性将被调用,并且用户将被重定向到另一个页面.

What happens in your code, is that first of all, MakeRequest() function is called, but it's immediately returned back (because ajax is asynchronouse), thus the next part of the onchange attribute would be called, and user would be redirected to another page.

要进行测试,请使您的ajax调用同步.请参见此处.

To test, make your ajax call synchronous. See here.