我是codeigniter的新手我不能不使用ajax请求从控制器获取数据我认为我在ajax调用中写入控制器函数的url时出错了
这是我的ajax调用的代码
$(document).ready(function(){ $("#fname").focusout(function(){ // alert(); $.ajax({ url: "<?php echo base_url();?>/proposal/ajax_load", type: 'POST', success: function(result){ $("#div1").html(result); } }); }); });这是我的控制器
class Proposal extends CI_Controller { public function ajax_load() { return ("Hello"); } }i'm new to codeigniter i can't not get data from the controller using the ajax request i think i do mistake in writing the url of the controller function in ajax call
here is the code of my ajax call
$(document).ready(function(){ $("#fname").focusout(function(){ // alert(); $.ajax({ url: "<?php echo base_url();?>/proposal/ajax_load", type: 'POST', success: function(result){ $("#div1").html(result); } }); }); });Here is my controller
class Proposal extends CI_Controller { public function ajax_load() { return ("Hello"); } }最满意答案
您在PHP中[Return, Echo]的含义混淆,
回声
echo - 输出一个或多个字符串
返回
return将程序控制返回给调用模块。 执行将在被调用模块调用之后的表达式处继续执行。
只要Ajax响应回调正在读取服务器响应[输出],就必须将输出发送到服务器。
public function ajax_load() { echo "Hello"; }进一步阅读: -
用简单的英语将PHP echo和PHP返回有什么区别?
在jQuery ajax调用方面,php echo和return之间的区别
一个简短而简单的答案
You are confuse between the meaning of [Return, Echo] in PHP,
Echo
echo — Output one or more strings
Return
return returns program control to the calling module. Execution resumes at the expression following the called module's invocation.
and as long as the Ajax response callback is reading a server response [output], you must send an output to the server.
public function ajax_load() { echo "Hello"; }Further reading :-
What is the difference between PHP echo and PHP return in plain English?
Difference between php echo and return in terms of a jQuery ajax call
a short and simple answer
更多推荐
发布评论