ajax 异步请求后台返回字符串赋值给js参数

来源:互联网 发布:eos utility for mac 编辑:程序博客网 时间:2024/06/05 03:26

很少用到,但有时候难免会有这样的需求,直接看代码吧。

function getText(){var c = $.ajax({url:'ajax/getText.action',dataType: 'text',type:'post',async: false,error: function(XMLHttpRequest, textStatus, errorThrown) {                          alert(XMLHttpRequest.status+"  "+XMLHttpRequest.readyState+"  "+textStatus);                }, success: function(text){return text;}});return c.responseText;}

这样就能拿到ajax请求拿到的值,并且getText()方法有返回值。这是个人的一点理解用法,如果有更好的解决办法还请指正。

——学习笔记,以备后需




0 0
原创粉丝点击