gpt4 book ai didi

javascript - 未捕获的语法错误 : Unexpected token < in JSON at position 0 at Function. 解析 [as parseJSON] ()

转载 作者:行者123 更新时间:2023-11-29 03:18:41 25 4
gpt4 key购买 nike

我在向 mysql 数据库添加数据时遇到问题,下面是代码(如果需要,我也可以添加 php 代码)。它说:

at Function.parse [as parseJSON] at Object.success (form.js:16) at u (jquery.min.js:2) at Object.fireWith [as resolveWith] (jquery.min.js:2) at k (jquery.min.js:2) at XMLHttpRequest.(jquery.min.js:2)

$(document).ready(function() {
$('form').submit(function(event) {
var json;
event.preventDefault();
$.ajax({
type: $(this).attr('method'),
url: $(this).attr('action'),
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
error: function (xhr, status, err) {
console.error(this.props.url, status, err.toString());
}.bind(this),
success: function(result) {
json = jQuery.parseJSON(result);
if (json.url) {
window.location.href = '/' + json.url;
} else {
alert(json.status + ' - ' + json.message);
}
},
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
ახალი აქციის დამატება
</h1>
<!-- <ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
<li><a href="#">Forms</a></li>
<li class="active">General Elements</li>
</ol>-->
</section>

<!-- Main content -->
<section class="content">
<div class="row">
<!-- left column -->
<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">

<!-- /.box-header -->
<!-- form start -->
<form action="/admin/addslider" method="post">
<div class="box-body">
<div class="form-group">
<label for="title">აქციის სათაური</label>
<input type="text" class="form-control" name="title" placeholder="აქციის სათაური">
</div>
<div class="form-group">
<label for="image">სურათის მიმაგრება</label>
<input type="file" name="img">

<!--<p class="help-block">Example block-level help text here.</p>-->
</div>

<div class="form-group">
<label>აქციის აღწერა</label>
<textarea class="form-control" name="description" rows="3" placeholder="Enter ..."></textarea>
</div>

<div class="form-group">
<label for="position">აქციის პოზიცია</label>
<input type="number" class="form-control" name="pos" min="1" max="20" >
</div>
</div>
<!-- /.box-body -->

<div class="box-footer">
<button type="submit" class="btn btn-primary">ატვირთვა</button>
</div>
</form>
</div>
<!-- /.box -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->

最佳答案

去掉这一行

json = jQuery.parseJSON(result);

您收到的响应似乎已经是一个 JSON 对象。

关于javascript - 未捕获的语法错误 : Unexpected token < in JSON at position 0 at Function. 解析 [as parseJSON] (<anonymous>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49360072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com