Intenté muchas formas de convertir mi XMLHTTPRequest en jQuery ajax pero no pude tener éxito.
Agradecería mucho si alguien pudiera ayudarme a resolver este problema.
aquí está mi código XMLHttpRequest:
var url = url; var xhr = new XMLHttpRequest(); xhr.open("POST", url); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { console.log(xhr.status); console.log(xhr.responseText); }}; var data = "ajax=1"; xhr.send(data);y aquí está mi intento pero no funciona
$.ajax({ url: "<?php echo $this->ui_url('onlineexamcats', 'all'); ?>", data: JSON.stringify("ajax=1"), type: "POST", processData: false, contentType: false, beforeSend: function(xhr){xhr.setRequestHeader('Content-Type', "application/x-www-form-urlencoded");}, success: function(res) { console.log(res); } });Prueba esto
$.ajax({ url: "<?php echo $this->ui_url('onlineexamcats', 'all'); ?>", data: "ajax=1", type: "POST", processData: false, success: function(res) { console.log(res); } });