新手求ajax返回值的问题

WBOY
Release: 2016-06-23 14:05:27
Original
906 people have browsed it

ajax返回值进入showmsg函数,然后alert(tips)出函数返回的值,但是总显示undefined,是不是返回类型的问题,新手求教~
function showmsg(ms)
{  
    var tips
  switch(ms)
{  
  case 'ding':
  tips='thanx votting';
  break
  case 'cai':
  tips='thanx u done';
  break
  case 'erro':
  tips='404 notfound';
  break; 
  default: tips='erro';
  break;
 
 }return tips;
 }


回复讨论(解决方案)

语法错误了吧,前面两个break 缺少结尾分号,先补齐了。之后在firebug控制台下看报什么错了。

在函数入口处 alert(ms) 观察一下传入的是什么

js 不强制需要行结束符“;”

在函数入口处 alert(ms) 观察一下传入的是什么

js 不强制需要行结束符“;”
其实我在firebug里面看到ajax返回多了2个空格,但是前面我用正则表达是清除了,但是就剩两个空格清不掉,不能完全清除。。返回的是"  1" 不是"1"
       var str=xmlHttp.responseText;
var pass= str.replace(/\r\n/g,"");

语法错误了吧,前面两个break 缺少结尾分号,先补齐了。之后在firebug控制台下看报什么错了。

其实我在firebug里面看到ajax返回多了2个空格,但是前面我用正则表达是清除了,但是就剩两个空格清不掉,不能完全清除。。返回的是"  1" 不是"1"
       var str=xmlHttp.responseText;
var pass= str.replace(/\r\n/g,"");

var pass= str.replace(/\s+/g,""); 这个才是清楚空格,你那个是清楚换行

var pass= str.replace(/\s+/g,""); 这个才是清楚空格,你那个是清楚换行
被你说对了~~没看清~~ 学得不好啊

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!