mysql - problems with ajax when using select nested with php mvc

I am new to this community and I registered for a precise problem.
I am working with mvc in php with mysql as bd, for each table I have created a raw where I read, create, edit and delete the records from the database, my question is the following, I have a PRODUCT table where I incorporate foreign keys to another table called SUBITEM where it has a foreign key to ITEM. Returning to the CRUD of the PRODUCT table at the time of creating a new record, I must enter the heading through a in html and depending on what is selected, load the second which is SUBITEM, for that I am using AJAX that to Through a POST method with a JSON data type, it sends the id to a script in php and it returns the values ​​filtered by the ID through a mysql query, which would then be passed to json with json_encode. the issue that throws me error "insert: 131 text status =: parsererror, error thrown: = SyntaxError: Unexpected token
ajax code that is in insert.php, is the view where the product is loaded
$.ajax({
data: { id : alumnos.val() },
url: 'data.php',
contentType: 'application/json; charset=utf-8',
type: 'post',
dataType: 'json',
beforeSend: function ()
{
item.prop('disabled', true);
},
success: function (data)
{
item.prop('disabled', false);
// Limpiamos el select
subitem.find('option').remove();
$(data).each(function(i, v){ // indice, valor
subitem.append('<option value="' + v.id + '">' + v.name + '</option>');
})
subitem.prop('disabled', false);
},
error: function(XMLHttpRequest, textStatus, errorThrown)
{
console.log('text status=:' + textStatus + ', error thrown:=' + errorThrown);
console.log(XMLHttpRequest.responseText);
item.prop('disabled', false);
}
});
data.php is the same hierarchical level with insert.php
include('../controllers/subitems.php');
$subitem = $this->subitem_model->getSubitemByItem($_POST['id']);
print_r(json_encode($data));
everything seems that the problem is due to the url address and that is why it automatically returns to the index through the .htaccess PD: I use sublimeText3 and xampp.
Answer
Solution:
first of all thanks for your reply. the address is ok I have tried it in ajax returning .html, the issue when I use json, I don't know if I do the conversion well. To the json_encode () I send an object, I don't know if it will be ok? or in necessary an array
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: your lock file does not contain a compatible set of packages. please run composer update
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.