如何使用 jQuery 在 ASP.NET WebService 中通过 AJAX 传递数据参数
当我运行不包含 parameters
的方法时,一切正常,但是当添加 parameters
运行该方法时,我收到 500 Internal Server Error
。我不确定我做错了什么,感谢您的帮助。
无法加载资源:服务器响应状态为 500(内部服务器错误)
下面是我当前使用的代码:
[WebMethod]
public static string UploadNewImage(string filePath,string ImageTitle,string ImageDescription,string ImageKeywords)
{
}
var parameters = "{'filePath':'" + fileuploadpathValue.val() + "','ImageTitle':'" +
titleValue.val() + "','ImageDescription':'" + descriptionValue.val() + "','ImageKeywords:'" +
keywordsValue.val() + "'}";
$.ajax({
type: "POST",
url: "../MainService.asmx/UploadNewImage",
contentType: "application/json; charset=utf-8",
data: parameters,
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
Everything works fine when I run the method without including parameters
, but when the method is run with parameters
added, I get a 500 Internal Server Error
. I am not sure what I am doing wrong, thanks for any help.
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Included below is the code that I am currently using:
[WebMethod]
public static string UploadNewImage(string filePath,string ImageTitle,string ImageDescription,string ImageKeywords)
{
}
var parameters = "{'filePath':'" + fileuploadpathValue.val() + "','ImageTitle':'" +
titleValue.val() + "','ImageDescription':'" + descriptionValue.val() + "','ImageKeywords:'" +
keywordsValue.val() + "'}";
$.ajax({
type: "POST",
url: "../MainService.asmx/UploadNewImage",
contentType: "application/json; charset=utf-8",
data: parameters,
dataType: "json",
success: AjaxSucceeded,
error: AjaxFailed
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您的参数更改为如下:
或按如下方式组合它们:
还要确保这里的 val() 没有一个为 null,也就是说您没有在上述任何控件上设置值,如果这是 csae,您将收到错误就像“Null 传递到不接受 null 值的参数”
change your parameters to as follows:
or combine them as follows:
also make sure that none of the val() here is null that is you dint have a value set on any of the above control if that is the csae you will get an error like "Null passed into parameter which does not accept null values"
问题出在您的 Json 格式中,
这在我的系统中有效,
如果您需要更多信息,请告诉我
The problem is in your Json format,
This is working in my system,
Let me know if u need more in that