Usermeta update with AJAX
-
Hi everyone!
I created a costum page that, given the link of a csv file uploaded to the media, updates me a meta data of the users. I used jquery (ajax) and php.
I thought of inserting the ajax post call within the loop of the csv lines to progressively update the metadata per user. I do not think it is the correct way to proceed, however, because the console gives me error 502 and 429. What am I doing wrong?
Previously I had managed the loading of the csv and the update of the users only through php but with a large number of users it becomes a very heavy operation and gives me a 502 error. I was looking for a less cumbersome solutionJquery
Query(document).ready(function( $ ){ $( "#test-click" ).click(function() { $.ajax({ type: "GET", url: 'FILE-CSV.csv', dataType: "text", success: function(data) {processData(data);} }); function processData(allText) { var allTextLines = allText.split(/\r\n|\n/); var headers = allTextLines[0].split(';'); //var lines = []; for (var i=1; i<allTextLines.length; i++) { var data = allTextLines[i].split(';'); if (data.length == headers.length) { var tarr = []; for (var j=0; j<headers.length; j++) { //tarr.push(headers[j]+":"+data[j]); tarr[headers[j]] = data[j]; //console.log(tarr['n']); $.ajax({ url:"/wp-json/bluenext/updatelesson", method: "POST", //data: post_id, data: {id : tarr['id'], id_lezione : tarr['id_lezione']}, success: function(response){ console.log(response); } }) } //lines.push(tarr); } } //console.log(lines); } }); });
PHP
function updatelesson(){ $user_id = json_decode($_POST['id']); $idlesson = json_decode($_POST['id_lezione']); llms_mark_complete( $user_id, $idlesson, 'lesson'); return $user_id; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Usermeta update with AJAX’ is closed to new replies.