首页 新闻 搜索 专区 学院

jquery ajax json中有反斜杠出错

0
悬赏园豆:30 [待解决问题]

var pars = "{fid:'"+ ForumID + "',title:'" + Title + "',mainBody:'"+ MainBody +"',sex:'0',age:'',sTime:'',mHistory:'',telphone:'',score:'0',ExpireDays:'7',code:'',tomemberId:'0',time:'"+ Date()+"'}";
        SetState(1);                     
       $.ajax({     
       type: "POST",     
       url: "/web/topic.asmx/AddTopic",     
       data: pars,
       contentType: "application/json; charset=utf-8",     
       dataType: "json",     
       success: function(originalRequest) {
           var Json = eval("(" + originalRequest.d + ")");
           //alert(Json.Redirect);
           if (!Json.Success) {
               alert(Json.Info);
               SetState(0);
           }
           if (Json.Redirect != null && Json.Redirect != '') {
               var reUrl = Json.Redirect;
               reUrl = reUrl.replace("amp;", "");
               reUrl = reUrl.replace("amp;", "");
               reUrl = reUrl.replace("amp;", "");
               reUrl = reUrl.replace("amp;", "");
               reUrl = reUrl.replace("amp;", "");
              
               if(reUrl.indexOf('browse') >=0)
               {
                    alert('提问成功!所述内容包含有关键字或链接,待管理员审核后可见!\n\t查看提问将进入该帖子所在板块!');                      
               }              
               if(typeof(reUrl.split("&uname=")[1])=='undefined')
               {
                 location.href ='/HtmlWeb/askjump.aspx?action=mtopic&url='+reUrl+'&nn=0&pp=0&fid='+ForumID+'';
               }              
               var reuname=reUrl.split("&uname=")[1].split("&pwd=");
               var mUrl=reUrl.split("&ref=")[1].split("&uname=");
               mUrl=mUrl[0];
               reuname=reuname[0];
               var repwd=reUrl.split("&pwd=")[1];
               if(reuname!=null || reuname!=''|| typeof(reuname)!='undefined')
               {
                  $('#txt1').val(reuname);
                  $('#txt_url').val(reUrl);
                  $('#txt_pwd').val(repwd);            
                 location.href ='/HtmlWeb/askjump.aspx?action=jump&url='+mUrl+'&nn='+reuname+'&pp='+repwd+'&fid='+ForumID+'';
               }
               else
               {              
                 location.href ='/HtmlWeb/askjump.aspx?action=mtopic&url='+reUrl+'&nn=0&pp=0&fid='+ForumID+'';
               }
               var adUrl = '';
               try {
                   adUrl = Json.Data[0];
               } catch (e) { }
               $('TipInfo').innerHTML = '<font color="red">' + Json.Info + '</font>';
               if (Json.Data.length > 2) {
               } else {
               
               }
           }
       } ,
      error: function(x, e) {
           alert(x.responseText);         
           SetState(0);
       }
    });    

 

如果Title和mainBody 中如果有\符号就会出错

冷火的主页 冷火 | 初学一级 | 园豆:4
提问于:2010-12-09 09:47
< >
分享
所有回答(2)
0

不用引号,如下试试:

var pars = {
fid: ForumID,
title: Title,
mainBody: MainBody,
sex:
'0',
age:
'',
sTime:'',
mHistory:
'',
telphone:
'',
score:
'0',
ExpireDays:
'7',
code:
'',
tomemberId:
'0',
time: Date()
};

 

鹤冲天 | 园豆:2379 (老鸟四级) | 2010-12-09 12:41
0

楼上正解!结贴吧!

勤劳的渔网工作者 | 园豆:572 (小虾三级) | 2010-12-09 16:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册