jQuery的AJAX获取返回值 [英] jquery ajax get return value

查看:116
本文介绍了jQuery的AJAX获取返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得HTML页面的'打印值。

我想下面的查询,但showGetResult()刚刚返回空值

但我的Apache服务器日志打印我访问的index.php当我尝试这个code。

(的index.php只是打印的HelloWorld)

 <脚本类型=文/ JavaScript的SRC =HTTP://$c$c.jquery.com/jquery-latest.js>< \脚本&GT ;
<脚本类型=文/ JavaScript的>
功能showGetResult(名)
{
     VAR的结果= NULL;
     jQuery.ajax({
        网址:HTTP://localhost/index.php,
        输入:'得到',
        数据类型:text / html的',
        成功:函数(数据)
        {
            警报(数据);
            结果=数据;
        }
     });
     返回结果;
}

文件撰写(showGetResult('测试'));
< / SCRIPT>
 

解决方案

我想你想要做的就是这一点。

 <脚本类型=文/ JavaScript的SRC =HTTP://$c$c.jquery.com/jquery-latest.js>< \脚本&GT ;
<脚本类型=文/ JavaScript的>
功能showGetResult(名)
{
     jQuery.ajax({
        网址:HTTP://localhost/index.php,
        输入:'得到',
        数据类型:text / html的',
        成功:函数(数据)
        {
            警报(数据);
            的document.write(数据);
        }
     });
}

showGetResult(测试);
< / SCRIPT>
 

i want to get the 'printed value' of html pages.

i tried below query, but showGetResult() just return 'null value'

but my apache server logs printed i accessed index.php when i try this code.

(index.php just print helloworld)

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"><\script>
<script type="text/javascript">
function showGetResult( name )
{
     var result = null;
     jQuery.ajax({
        url: 'http://localhost/index.php',
        type: 'get',
        dataType: 'text/html',
        success:function(data)
        {
            alert(data);
            result = data;
        } 
     });
     return result;
}

document.write(showGetResult('test'));
</script>

解决方案

I think what you want to do is this.

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"><\script>
<script type="text/javascript">
function showGetResult( name )
{
     jQuery.ajax({
        url: 'http://localhost/index.php',
        type: 'get',
        dataType: 'text/html',
        success:function(data)
        {
            alert(data);
            document.write(data);
        } 
     });
}

showGetResult('test');
</script>

这篇关于jQuery的AJAX获取返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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