Reputation: 657
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(/"/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.
Appreciate if someone can help me on this issue. Thanks.
Upvotes: 0
Views: 237
Reputation: 3922
you can use replace function.
var data="http://localhost:8000/folder/"+category1+"/test.pdf"
data=data.replace(/"/g,'')
console.log(data)
Upvotes: 1