使用json / jquery将更长的字符串发布到Web服务 [英] Post a longer string to a webservice using json/jquery
问题描述
我向Webservice发送的数据很少。
=============================== ====
I am sending few data to Webservice.
===================================
function test() {
var dataURL = "data:image/png;base64,iVBORw0KGgoAAAAN";
var dataUrlJson = [{ "imageData": dataURL }];
$.ajax({
type: "POST",
url: "LP18WS.asmx/CreateMarkers",
// The key needs to match your method's input parameter (case-sensitive).
data: JSON.stringify({ Markers: dataUrlJson }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) { alert(data); },
failure: function (errMsg) {
alert(errMsg);
}
});
==== === ====================================
LP18WS.asmx文件中的
< br $>
==================
===========================================
in LP18WS.asmx file
==================
public class Marker
{
string imageData { get; set; }
}
[WebMethod]
public string CreateMarkers(List<Marker> Markers)
{
foreach (Marker mk in Markers)
{
//string aa = mk.imageData//Error
}
return "Received " + Markers.Count + " markers.";
}
============================== ==============
调试器正在执行而没有任何错误。
但我是无法读取数据。
任何人都可以告诉我如何读取数据(即标记[imageData])
============================================
Debugger is hitting and executing without any error.
But I am not able to read the data.
Can anyone tell me how to read the data (ie. Markers["imageData "])
推荐答案
.ajax({
type: POST,
url:< span class =code-string> LP18WS.asmx / CreateMarkers,
/ / 密钥需要匹配方法的输入参数(区分大小写)。
data: JSON .stringify({Markers:dataUrlJson}),
contentType: application / json; charset = utf-8,
dataType: json,
成功: function (data){alert(data); },
失败: function (errMsg){
alert(errMsg);
}
});
.ajax({ type: "POST", url: "LP18WS.asmx/CreateMarkers", // The key needs to match your method's input parameter (case-sensitive). data: JSON.stringify({ Markers: dataUrlJson }), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { alert(data); }, failure: function (errMsg) { alert(errMsg); } });
======================= ====================
LP18WS.asmx文件中的
========= =========
===========================================
in LP18WS.asmx file
==================
public class Marker
{
string imageData { get; set; }
}
[WebMethod]
public string CreateMarkers(List<Marker> Markers)
{
foreach (Marker mk in Markers)
{
//string aa = mk.imageData//Error
}
return "Received " + Markers.Count + " markers.";
}
============================== ==============
调试器正在执行而没有任何错误。
但我是无法读取数据。
任何人都可以告诉我如何读取数据(即标记[imageData])
============================================
Debugger is hitting and executing without any error.
But I am not able to read the data.
Can anyone tell me how to read the data (ie. Markers["imageData "])
这篇关于使用json / jquery将更长的字符串发布到Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!