【发布时间】:2014-07-08 05:15:23
【问题描述】:
我有两个页面,一个是 customform.php,另一个是 preview.php。
我想使用 jquery post 方法发送一些数据,这些数据是 customform.php 上某些文本字段的值。但我不希望页面加载。所以我为这项工作使用了一些 JQuery 代码。但现在为我工作。
customform.php 上的 html 代码是:
<form action="#" method="post">
<input type="text" value="" id="text1">
<input type="text" value="" id="text2">
<input type="button" value="preview" id="preview">
</form>
customform.php 上的 jQuery 代码是:
$('#previewph').click( function() {
var v1 = $.('#text1').val();
var v2 = $.('#text2').val();
alert("Mail: " + v1 + " Message: " + v2);
$.post( "http://www.lexiconofsustainability.com/lex_tmp2/preview/" ,{ name : v1 , title :v2 });
window.open("http://www.lexiconofsustainability.com/lex_tmp2/preview/", '_blank');
});
在 preview.php 上,我想检索值形式的 post 方法并回显它们。
<?php
echo $authorname = $_POST['name'];
echo $posttitle = $_POST['title'];
?>
【问题讨论】:
-
$.post(URL, DATA, function(data) { console.log(data); })third (3)选项 (function(data){..etc) 吗?那就是接收php脚本的响应。 -
这正是我对函数(数据)的理解,你能否给我上面例子中我需要在函数(数据)中写的代码。
-
第一次在这篇文章中有些东西对我有用....我正在努力。成功后我会通知你
-
@Darren 我提出了一个问题。这里[stackoverflow.com/questions/24628008/….你能看看这个吗?