如何在codeigniter php中的ajax请求中写入url?(how to write url in ajax request in codeigniter php?)

编程入门 行业动态 更新时间:2024-10-28 17:21:01
如何在codeigniter php中的ajax请求中写入url?(how to write url in ajax request in codeigniter php?)

我是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

更多推荐

本文发布于:2023-07-22 06:58:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1217905.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   php   codeigniter   ajax   write

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!