I have some jquery/php code which uses ajax to call another page.

我有一些jquery/php代码,它使用ajax调用另一个页面。

var pall_id = $(this).attr('id');
        $.ajax({ 
           type: "POST",
           url: "do_history.php?pall_id="+pall_id,   
           success: function (msg) {
                alert (msg);

            },
            error: function (XMLHttpRequest, textStatus, errorThrown)
            {   
                alert('Error submitting request.'); 
            } 
        });

However what do I do to get the value of msg? e.g. if do_history.php is simply:

然而,我怎么做才能得到味精的价值呢?例如,如果do_history。php是简单的:

<?php

$text="text";
return $text;

?>

would 'msg' not be "text" so when I alert(msg); I would get "text" popping up on my screen.

“msg”不是“text”,所以我提醒(msg);我会在屏幕上弹出“文本”。

What do I need to do to return a string value? Any ideas?

要返回一个字符串值,我需要做什么?什么好主意吗?

Thanks,

谢谢,

4 个解决方案

#1


1

Use echo $text; and in your $.ajax options add dataType: 'text'.

使用echo $文本;和你的美元。ajax选项添加数据类型:“文本”。

However, a better solution would be using dataType: 'json' and then echo json_encode($text); - in this case $text could also be an array/object/number and it would be the appropriate type in the JavaScript function .

但是,更好的解决方案是使用数据类型:'json',然后回显json_encode($text);在这种情况下,$text也可以是一个数组/对象/数字,它将是JavaScript函数中适当的类型。

更多相关文章

  1. jQuery——将title属性用作悬停的文本,但只在同一父类中使用。
  2. 如何在java脚本中获取节点内部文本?
  3. jquery 监控文本框键盘事件(回车事件),附常用keycode值。
  4. 使用jQuery更新textarea值更改的文本
  5. 输入-文本对齐:用jQuery右填充输入
  6. 如何使用javascript/jquery获取文本框数组值
  7. 解析PHP的基本文本输出
  8. 在体html中搜索文本的最佳方法是什么?
  9. 通过ajax POST提交nicEdit文本编辑器的值,不起作用

随机推荐

  1. android4.4 Launcher主菜单界面同样采用
  2. Android-给图片添加暗影
  3. Android中SQLite应用详解(很详细)
  4. Android(安卓)-- The Manifest File
  5. android代码库之执行Shell命令或者脚本
  6. Android中Activity组件详解
  7. Android(安卓)EditText截获与监听输入事
  8. Android(安卓)图片大小超过预算的VM:java.
  9. Android(安卓)TimeUtil
  10. android ACTION_BOOT_COMPLETED接收不到