栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

通过AJAX提交有关选择更改的表单

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过AJAX提交有关选择更改的表单

使跨浏览器

onchange
事件和AJAX请求正常工作并非易事。我建议您使用某种javascript框架,该框架可以抽象掉所有跨浏览器问题,因此您不必担心它们。

尝试一个js框架

jQuery就是一个这样的框架,它具有诸如这样的方法,

.change()
该方法将处理程序附加到诸如元素之类的change事件上,
<select>
.get()
执行GET请求。

这里有一些代码可以帮助您入门:-

// The $ is the shorthand for a jquery function, you can then use jquery // selectors which are essentially the same as css selectors, so here// we select your select field and then bind a function to // it's change event handler$('select.changeStatus').change(function(){    // You can access the value of your select field using the .val() method    alert('Select field value has changed to' + $('select.changeStatus').val());   // You can perform an ajax request using the .ajax() method   $.ajax({       type: 'GET',      url: 'changeStatus.php', // This is the url that will be requested      // This is an object of values that will be passed as GET variables and       // available inside changeStatus.php as $_GET['selectFieldValue'] etc...      data: {selectFieldValue: $('select.changeStatus').val()},      // This is what to do once a successful request has been completed - if       // you want to do nothing then simply don't include it. But I suggest you       // add something so that your use knows the db has been updated      success: function(html){ Do something with the response },      dataType: 'html'    });});

一些参考资料会比我的解释更好

请注意,此代码才能正常工作,您需要在页面上包含带有

<script>
标签的jquery库。

有关使用jquery的快速入门指南,请参见此处

这里是有关如何使用jQuery

ajax()
方法的初学者教程



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/393463.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号