如何从字符串中删除双引号和单引号以及如何传入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个回答



您有两种选择:</ p>

逃生</ h2>

你可以通过反斜杠转义双引号,如下所示:</ sub> </ p>

</ p>





  $ review_title =”New \“home \”离开家时在村里“;

console.log($ review_title); </ code> </ pre>

< / div>

</ div>

替换</ h2>

</ p>





  $ review_title ='新的”家“离家时在村里';

$ review_title = $ review_title.replace(/ ['”] + / g, “”);

console.log($ review_title); </ code> </ pre>

</ div>

</ div>

</ div>

展开原文

原文

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>

driuwt9557
driuwt9557 我不知道这个你可以帮助请ajax调用放置.replace()函数的位置
大约 2 年之前 回复
doutan1875
doutan1875 你应该在ajax调用之前使用它,在你从函数中获得标题之后。
大约 2 年之前 回复
dtf54486
dtf54486 谢谢@Pedram,但你可以与我的ajax调用集成吗? 请
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问