我正在尝试将选定的选项值和jQuery文本输入插入数据库,但是我得到了一个
未捕获的SyntaxError:意外的标识符
<div class="text-field" id="catUp" >
<form id="upload_category" method="post" >
<div class="text-inside">
<select id="select-category">
<option value="audio">Audio,Video</option>
<option value="electro">Electrocasnice</option>
<option value="ingrijire">Ingrijire personala</option>
<option value="pc">PC</option>
<option value="telefoane">Tablete,telefoane</option>
</select><br><br>
<div id="insert-category">Nume Categorie<br>
<input type="text" name="input-categorie" /><br><br>
</div>
<input type="submit" name="sumit" value="Adauga categorie" id="catButton" class="button" /><br><br>
</div>
</form>
</div>
$('#upload-category').on('submit', function(){
var getCategory = '';
var getCategoryName = $('#insert-category').val();
$('#select-category').change(function(){
var selectedCat = $('#select-category option:selected');
getCategoryName = selectedCat;
})
var items = {
'categorie': getCategory,
'nume':getCategoryName
}
$.ajax({
url:'category.php',
type: 'post',
contentType: 'application/json',
dataType: 'json'
data:JSON.stringify(items)
});
});
最佳答案
$.ajax({
url:'category.php',
type: 'post',
contentType: 'application/json',
dataType: 'json', //you forgot comma here
data:JSON.stringify(items)
});
您在此行
dataType: 'json',
之后忘记了逗号