I am using twig and symfony 2.8. In a twig template I make an AJAX call to a php script. this is the simplified AJAX call:
$.ajax({
url:'{{ (path('search')) }}',
type: "POST",
dataType: "json",
data: {
"fields": {
"invoiceNo" : $("#invoiceNo").val()
}
},
async: true,
success: function (data)
{
}
});
The response data is an array containing the id of some invoices. I want to use the path function in twig to generate urls of invoices based on the IDs in data.
I did this:
for (var i = 0; i < data.length; i++) {
var url = {{ path('invoice_url', {'invoiceId' : data[i]['id']}) }}
}
However I am getting an error that the variable data does not exist. I suppose, this is because data is a runtime variable.
any idea how I can use AJAX call result (data) to generate the urls?
FOSJSRoutingBundleto resolve theurlto where u want to post yourajax-call