如何运行的提交按钮无刷新/重新加载页面的PHP code [英] how to run php code on submit button without refreshing/ reloading the page
问题描述
我要执行的提交按钮点击无刷新/重新载入我的网页一些PHP code。可能吗?另外我有在页面加载javascript函数,这就是为什么我不希望我的刷新网页。 在此先感谢。
I want to execute some php code on submit button click without refreshing/reloading my page. Is it possible? also i have javascript function on page load that's why i don't want to refresh my page. thanks in advance.
<?php
if(isset($_POST["search"]))
{
$show = "SELECT * FROM data";
$rs = mysql_query($show) or die(mysql_error());
$add_to_textbox = "<input type='button' name='btn' value='add' />";
#****results in Grid****
echo "<table width='360px' border='1' cellpadding='2'>";
$rowID=1;
while($row = mysql_fetch_array($rs))
{
echo "<tr>";
echo "<td width='130px' id='name.$rowID.'>$row[Name]</td>";
echo "<td width='230px' id='link.$rowID.'><a href = '$row[Link]'>$row[Link]</a></td>";
echo "<td width='130px' onclick='Display($rowID);'>$add_to_textbox</td>";
echo "</tr>";
$rowID++;
}
echo "</table>";
#**********************
mysql_free_result($rs);
}
?>
<script type="text/javascript">
function Display(rowID){
var linkVal = document.getElementById('link'+rowID+'').innerHTML.replace(/<\/?[^>]+(>|$)/g, "\n");
document.getElementById("name").value = document.getElementById('name'+rowID+'').innerHTML;
document.getElementById("link").value = linkVal;
}
</script>
这是我的code
here is my code
推荐答案
那么,你需要使用的JavaScript / AJAX。
Well, you need to use the javascript / ajax.
例如:您提交的链接(A HREF为的exaple),加叩至js函数 submitMe
并传递任何变量,你需要
Example: on your submit link (a href for exaple), add call-in-to js function submitMe
and pass on whatever variables you need
function submitMe() {
jQuery(function($) {
$.ajax( {
url : "some_php_page.php?action=getsession",
type : "GET",
success : function(data) {
alert ("works!"); //or use data string to show something else
}
});
});
}
如果你想要动态地改变一些内容,这是简易,你只需要创建标签,并指定ID对他们说:&LT; DIV ID =动态&GT; &LT; / DIV&GT;
IF you want to change some content dynamically, it is easy- you just need to create tags, and assign ID to them : <div id="Dynamic"> </div>
然后使用加载这两个标记之间的内容
Then you load ANYTHING between those two tags using
document.getElementById("Dynamic").innerHTML = "<b>BOOM!</b>";
意思是说你们两个标记之间的呼叫区域和装载的东西放进去。用同样的方法,你从那个地方的数据:
Meaning that you calling area between two tags and loading something into them. The same way you GET data from that place:
alert(document.getElementById("Dynamic").innerHTML);
请阅读本: <一href="http://www.tizag.com/javascriptT/javascript-getelementbyid.php">http://www.tizag.com/javascriptT/javascript-getelementbyid.php
此外,游戏和实验DOM元素,并了解它们是如何相互作用的。也不是很难,只是需要一些时间来掌握所有的概念。
In addition, play and experiment with DOM elements and learn how they interact. It is not hard, just takes some time to grasp all concepts.
这篇关于如何运行的提交按钮无刷新/重新加载页面的PHP code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!