我在“网站 A”上有一个表格,该表格发布到“网站 B”。代码包括在下面。
我无法从目标域获得成功或返回消息。
有什么建议么?我究竟做错了什么?
<script type="text/javascript">
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
$(document).ready(function(){
$("#submit").bind("click", function(){
//turn form into json
var formData = $("#digForm").serializeObject();
var jsonData = JSON.stringify(formData);
alert(jsonData);
$.ajax({
url: URL,
data: jsonData,
dataType: 'jsonp',
cache: false,
success: function (data) {
alert(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
})
});
</script>
这是控制器:
[HttpPost]
public ActionResult Index(string submission)
{
SubmissionModel model = new SubmissionModel();
//validate everything we need is here
var serializer = new JavaScriptSerializer();
// get json data from url
var json = submission;
var submissionData = serializer.Deserialize<SubmissionModel>(json);
model.SiteID = submissionData.SiteID;
model.FirstName = submissionData.FirstName;
model.LastName = submissionData.LastName;
model.Email = submissionData.Email;
model.Comments = submissionData.Comments;
model.Like = submissionData.Like;
model.Dislike = submissionData.Dislike;
model.SubmitDate = DateTime.Now;
db.Submissions.Add(model);
db.SaveChanges();
return View();
}