Rzj Hayabusa
Rzj Hayabusa

Reputation: 657

How to replace " output in jQuery?

I have this ajax request to display data into a modal.

But I'm stuck at adding the value into URL link. The code is as below.

In console, I see that the output has quot in it. How do I replace/remove it ? I cannot add the output into pdfUrl variable. Output in console show like this

GET http://localhost:8000/folder/"+category1+"/test.pdf 404 (Not Found)

test.js

$.ajax({
    url: "/getpdf",
    type: "GET",
    dataType: "json",
    data: {"id": id},
    success: function(data)
    {  
        var ar = data;  

        var category        = ""; 

        for (var i = 0; i < ar.length; i++) 
        { 
            category        = ar[i]['category'];    
        }     

        var category1 = category.replace(/&quot;/g, '\\"');
        console.log(category1);

        var pdfUrl = "{{ URL::to('/folder/"+category1+"/test.pdf') }}";
        $(".iframeDoc1").attr("src", pdfUrl).show();  

        $('#modal_show').modal({
            show: true
        });  

    },
    error: function(error){
            console.log("Error:");
            console.log(error);
    }
});  

Output in console.

enter image description here

Appreciate if someone can help me on this issue. Thanks.

Upvotes: 0

Views: 237

Answers (1)

Negi Rox
Negi Rox

Reputation: 3922

you can use replace function.

var data="http://localhost:8000/folder/&quot;+category1+&quot;/test.pdf"
data=data.replace(/&quot;/g,'')
console.log(data)

Upvotes: 1

Related Questions