如何在不刷新的情况下将数据插入字段? [英] How to insert data into field without refresh?
问题描述
我需要知道如何在不刷新字段的情况下从数据库添加数据?我的意思就像电子邮件中添加联系人的工作一样。如果我点击添加按钮,我需要打开一个小窗口和其中的联系人。如果我检查一个或两个联系人,然后按插入,它应该被插入'收件人'字段,而不刷新父页.. !!
I need to know how can I add data from the database without refreshing the field ? I mean just like the working of Add Contacts in the Email. If I click the 'Add' button, I need to open a small window and contacts within it. If I check one or two contacts and press insert, it should be inserted in the 'To' field without refreshing the parent page..!!
我该怎么做在PHP或JavaScript?请帮助我:)
How can I do that in php or JavaScript ? Please help me :)
推荐答案
您需要使用ajax来执行此操作。 Ajaxform是一个很好的插件,用于动态地向表单中的页面添加数据。你也可以使用jquery中的$ .ajax。 http://jquery.malsup.com/form/#ajaxForm
You'll need to use ajax to do so. Ajaxform is great plugin for dynamically adding data to a page from a form. You can use $.ajax from jquery as well. http://jquery.malsup.com/form/#ajaxForm
$(document).ready(function() {
var options = {
target: '#output1', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
};
// bind form using 'ajaxForm'
$('#myForm1').ajaxForm(options);
});
或常规ajax
$.ajax({
url : url,
data : {name : name}
dataType : 'json',
success : function(data) {}
});
这篇关于如何在不刷新的情况下将数据插入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!