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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀