admin管理员组文章数量:1392076
I'm not entirely familiar with the MVC model and I cannot get my head around it, however I am trying to simplify things by having my page design separate from my logic. I have my basic template all set up, and I would like hyperlinks to open PHP files within the same page.
For instance:
Next Page
rather than opening nextpage.php, I would like the contents of nextpage.php to open the code into a div on the same page. The contents of nextpage.php will contain some PHP code, and some HTML forms
I'm assuming AJAX is the right approach to this, but any suggestions is greatly appreciated.
Thanks
I'm not entirely familiar with the MVC model and I cannot get my head around it, however I am trying to simplify things by having my page design separate from my logic. I have my basic template all set up, and I would like hyperlinks to open PHP files within the same page.
For instance:
Next Page
rather than opening nextpage.php, I would like the contents of nextpage.php to open the code into a div on the same page. The contents of nextpage.php will contain some PHP code, and some HTML forms
I'm assuming AJAX is the right approach to this, but any suggestions is greatly appreciated.
Thanks
Share Improve this question asked Sep 6, 2013 at 10:59 Dave MeliaDave Melia 3172 gold badges5 silver badges17 bronze badges 3- Yes, Ajax is appropriate for this. – The Alpha Commented Sep 6, 2013 at 11:02
- include your PHP and Ajax code in question – Tahir Yasin Commented Sep 6, 2013 at 11:02
- link that's the code I wish to display from a .php file onto the same page. – Dave Melia Commented Sep 6, 2013 at 11:23
3 Answers
Reset to default 3take a look to: http://api.jquery./load/
you can load only on part of a page in a html element
$('#result').load('ajax/test.html #container');
Ajax function
$(document).ready(function(){
$("#submitBtn").click(function() {
$.ajax({
type: "POST",
url: "request.php", //Your required php page
data: "id="+ studentid, //pass your required data here
success: function(response){
$('#output').html(response);
}
});
return false;
});
});
request.php
<?php
$student_id= $_POST['id']; //The data that is passed from tha ajax function
$message = "The id you have entered is".$student_id;
echo $message;//This will be obtained in the ajax response.
I would use a framwork like jQuery and use the ajax() function. Then you must simple execute the statement and in the success handler set content of the div to the received data.
本文标签: javascriptUsing AJAX to execute PHP codeStack Overflow
版权声明:本文标题:javascript - Using AJAX to execute PHP code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744766781a2624089.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论