douzong5473 2018-05-19 11:25
浏览 251
已采纳

如何从字符串中删除双引号和单引号以及如何传入ajax调用

I need to remove all double quotes,single quotes using jQuery AJAX in with google language translator in PHP when i change onchange() it does not translate the string or character if double quotes found. My code below:

HTML:

<select name="langid" id="langid<@=review_id@>" class="guest clearfix" style="width: 150px;height: 29px;" onchange='translate_text("<@=review_id@>","<@=review_title@>","<@=your_view@>","<@=neg_review@>");'>   
</select>

JavaScript/jQuery:

function translate_text($review_id,$review_title,$your_view,$neg_review) 
{


 var sel = jQuery('#langid'+$review_id).val();
     var url=serverurl+'index.php/feedback';
        showLoadingBar();
        if(sel == 0)
        sel = 'en';



 var passDataAsStr="opcode=translate_text&positivereview="+
$your_view+"&negativereview="+$neg_review+"&title="+$review_title+"&lang="+sel;


            jQuery.ajax({


         type: "POST",
                 url: url,
                //async : false,
                data: passDataAsStr,
                success: function(response) {
                hideLoadingBar();
                // console.log(response);
                    jQuery('#btnclose'+$review_id).show();
                    jQuery('#trans_div'+$review_id).show();
                    var res = jQuery.parseJSON(response);
                    console.log(res['title']);
                    console.log(res['posrev']);
                    console.log(res['negrev']);
                    jQuery('#titleid_'+$review_id).text(res['title']);
                    jQuery('#positiveid'+$review_id).text(res['posrev']);
                    jQuery('#negativeid'+$review_id).text(res['negrev']);

                      }
              });
}

When I want change the language translator it does not change

Suppose $review_title = "New "home" away from home when in village", it does not translate in another languages,because double quotes "home" at the middle of string

Any body having any idea please help to sort it out. Thanks

  • 写回答

1条回答 默认 最新

  • doutaoer3148 2018-05-19 11:53
    关注

    You have two choice:

    Escape

    You can escape double quotes by back slash like this:

    $review_title = "New \"home\" away from home when in village";
    console.log($review_title);

    Replace

    $review_title = 'New "home" away from home when in village';
    $review_title = $review_title.replace(/['"]+/g, "");
    console.log($review_title);

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 cplex运行后参数报错是为什么
  • ¥15 之前不小心删了pycharm的文件,后面重新安装之后软件打不开了
  • ¥15 vue3获取动态宽度,刷新后动态宽度值为0
  • ¥15 升腾威讯云桌面V2.0.0摄像头问题
  • ¥15 关于Python的会计设计
  • ¥15 聚类分析 设计k-均值算法分类器,对一组二维模式向量进行分类。
  • ¥15 stm32c8t6工程,使用hal库
  • ¥15 找能接spark如图片的,可议价
  • ¥15 关于#单片机#的问题,请各位专家解答!
  • ¥15 博通raid 的写入速度很高也很低