I have a problem related to an array data which fetched from an external file. The script used is AJAX ina .js file. After fetching the data from an external file (.php), the array data showed a comma in front of each item. Is there any problem with my code? If there is any way to solve this problem, please do let me know.
Sample code:
var i = 1;
var loadPcs = [];
var deststop = [];
var datestop = [];
while (i <= counter)
{
deststop[i]= encodeURI(document.getElementById('stop'+i).value);
deststop[i] = deststop[i] + ("%");
datestop[i]= encodeURI(document.getElementById('depDate'+i).value);
datestop[i] = datestop[i] + ("%");
notes[i]= encodeURI(document.getElementById('notes'+i).value);
notes[i] = notes[i] + ("%");
i = i + 1;
}
{
var stopdest = deststop;
var stopdate = datestop;
http.open('get', 'insert.php?&deststop='+stopdest+'&datestop='+stopdate+'&loadPcs='+loadPcs+'¬es='+notes+'&counter='+counter);
}
Try this:
Instead of using array take a string variable , take a look at below code
Replace all arrays with a string variable and append data like done in above code.