如何将javascript变量返回给Ajax? [英] How to return javascript variable to Ajax?

查看:68
本文介绍了如何将javascript变量返回给Ajax?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道我在使用ajax调用php时如何将javascript变量返回给ajax而不是字符串值.有关更多详细信息,请参见下面的示例:

Does anyone know how can I return the javascript variable to ajax instead of string value while I using ajax to call the php. Please see below example for more details:

Ajax:

    //Ajax Param 
    var paramList = "Action=make_process";

    ajaxRequest = $.ajax({
            url: "admin.php",
            type: 'POST',
            data: paramList,
            error: function(){
                  //error message here
            },
            success: function(data){
                 //read return javascript variable here;
            }   
        });   

PHP:

public function validationChk()
    {
        $error_msg['error_msg'][] = array("msg"=>"hello");
            $error_msg['error_msg'][] = array("msg"=>"hi");

        echo "var ErrorMapping = " . json_encode($error_msg). ";\n\n";          
        exit;
    }

推荐答案

您想知道如何从AJAX响应中返回吗?

You wondering how you can return from an AJAX response?

然后查看此jQuery FAQ答案.

这篇关于如何将javascript变量返回给Ajax?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆