jQuery的提交表单,然后显示结果在现有的div [英] jquery submit form and then show results in an existing div
问题描述
我有一个简单的文本输入表单提交时,需要获取一个PHP文件(通过输入到文件),然后把结果(只一行文本),并将其放置在一个div和褪色的DIV眼帘。
I have a simple one text input form that when submitted, needs to fetch a php file (passing the inputs to the file) and then take the result (just a line of text) and place it in a div and fade that div into view.
这是我现在有
<form id=create method=POST action=create.php>
<input type=text name=url>
<input type="submit" value="Create" />
<div id=created></div>
我需要的是create.php?URL =输入的结果,可以动态加载到名为创建的分区。
What I need is the results of create.php?url=INPUT, to be dynamically loaded into the div called created.
我有jQuery的形式剧本,但我一直没能得到它的工作的权利。但我有库加载(文件)。
I have the jquery form script, but i haven't been able to get it to work right. But I do have the library loaded (the file).
推荐答案
这code应该这样做。你不需要这个插件的东西,像这样简单:
This code should do it. You don't need the Form plugin for something as simple as this:
$('#create').submit(function() { // catch the form's submit event
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
$('#created').html(response); // update the DIV
}
});
return false; // cancel original event to prevent form submitting
});
这篇关于jQuery的提交表单,然后显示结果在现有的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!