从jQuery.get返回的responseText() [英] return responseText from jQuery.get()

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

问题描述

我试图做这样的事情:

var msg = $.get("my_script.php");

我认为味精会被设置为my_script.php,即返回的文本该jqXHR对象的responseText。 这显然​​不工作,可以如此味精始终设置为[对象XMLHtt prequest]

I thought msg would be set to the text returned by my_script.php,i.e. the responseText of the jqXHR object. It apparently doesn't work like that as msg is always set to "[object XMLHttpRequest]"

有一个快速1号线的方法做我想要什么?

Is there a quick 1 line way to do what I want?

感谢。

推荐答案

经过一些测试,我最终找到一个解决办法。

After some testing, I ended up finding a solution.

我需要调用是同步的,$不用彷徨速记功能永远asynchonous,所以我将需要使用$阿贾克斯,像这样的:

I need the call to be synchronous, $.get shorthand function is always asynchonous, so I will need to use $.ajax, like this:

var msg = $.ajax({type: "GET", url: "my_script.php", async: false}).responseText;

我不认为这是一个更好的方式来做到这一点,谢谢您的回答。

I don't think there is a better way to do this, thanks for your answers.

这篇关于从jQuery.get返回的responseText()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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