尽管服务器发送了响应(在调试器中看到),但从ajax发送的发布请求却出现500错误。响应设置为正确的URL,并由服务器执行。服务器返回结果,但在浏览器中显示错误状态500。
这是用于ASP.net MVC小型应用程序。
import Vue from 'vue';
import StarsWithLabel from '../components/StarsWithLabel';
import VueResource from 'vue-resource';
Vue.use(VueResource);
export default {
components: {
'star-with-label': StarsWithLabel,
},
data: function () {
return {
config: window['endpointBookmakersProperties'],
comment_content: null,
showReview: false,
showReviewForm: true,
comment: null,
comment_id: null,
error_msg: '',
showErrorMsg: false,
pendingRatings: [],
};
},
methods: {
onSubmit: function () {
const request = this.config['comment_url'];
const requestRating = this.config['rating_url'];
this.$http.post(
request,
{
author_name: this.config['author_name'],
author_email: this.config['author_email'],
user_id: this.config['post_author'],
author: this.config['post_author'],
post: this.config['post'],
content: this.comment_content,
},
{
emulateJSON: true,
headers: { 'X-WP-Nonce': this.config['nonce'] }
}
).then(response => {
// disable form
this.showReviewForm = false;
// show review
this.showReview = true;
// get comment id
this.comment_id = response.body.id;
// get body data
console.log(response.body);
// update bookmaker rating
}, response => {
// error callback
this.showErrorMsg = true;
this.error_msg = response.body.message;
});
if (this.comment_id !== 'undefined') {
this.$http.post(
requestRating,
{
user_id: this.config['post_author'],
bookmaker_id: this.config['post'],
properties_id: 'bk_goodwill',
value: 5,
comment_id: this.comment_id,
},
{
emulateJSON: true,
headers: { 'X-WP-Nonce': this.config['nonce'] }
}
).then(response => {
// get status
console.log(response.status);
// get status text
console.log(response.statusText);
// get body data
console.log(response.body);
// update bookmaker rating
}, response => {
// error callback
this.showErrorMsg = true;
this.error_msg = response.body.message;
});
}
},
onClickChild (value) {
console.log(value);
}
},
};
</script>
<template>
<div>
<div v-if="showReview" class="current_user_review">
<h3>Ваш отзыв:</h3>
<div class="user-review">{{this.comment_content}}</div>
</div>
<div v-if="showErrorMsg">
<h3>Произошла ошибка:</h3>
<div class="error-review">{{this.error_msg}}</div>
</div>
<div v-if="showReviewForm">
<h3>Оставить отзыв</h3>
<div>
<span @sent-rating-in-parent="onClickChild"></span>
</div>
<div class="add_reviews_form">
<div class="bookmaker-ratings-items">
<div v-for="(value, property) in config['bookmaker_properties']" :key="property.id" class="rating-items" :id="property">
<star-with-label :label="value" :property="property"></star-with-label>
</div>
</div>
<form v-on:submit.prevent="onSubmit" class="new_review_form">
<textarea rows="8" cols="20" v-model="comment_content"></textarea>
<input type="submit" value="Отправить" class="btn btn-default btn-lg2 btn--is-s1">
</form>
</div>
</div>
</div>
</template>```
这在C#中:
$(window).on("load", function () {
console.log("LOADING");
$.post("/Play/Word", {}, function (data) {
console.log(data['content']);
});