ラベル returned の投稿を表示しています。 すべての投稿を表示
ラベル returned の投稿を表示しています。 すべての投稿を表示

2012年3月28日水曜日

Reset scroll after call back

Hi,

How do I reset the scroll position of the page when a call back has returned?

Cheers, WT.

http://aspnet.4guysfromrolla.com/articles/111704-1.aspx

assign using client side script

document.body.scrollLeft = 0;

document.body.scrollTop = 0

2012年3月24日土曜日

Return json from xml document

I am trying to return a json object from an XML docuement, but the returned object is not in json format. What am i misisng?

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, XmlSerializeString:=False)> _
PublicFunction GetFormObject( _
ByVal strFileLocAsString)As XmlDocument
Try
Dim xmlDocAsNew XmlDocument
xmlDoc.Load(strFileLoc)
Return xmlDoc
Catch allExceptionsAs Exception
MsgBox(HttpUtility.HtmlEncode(allExceptions.Message))
ReturnNothing
EndTry
EndFunction

TIA

Is the XmlDocument class marked as serializable? It needs to be in order to be remoted by JSON.


Hi Scott,

How does one mask an xml document as serializable?

Ron Tornambe


Hi,

I am not sure, but here may be the answer:http://forums.asp.net/p/1054378/1496599.aspx

I am not sure, did you try to specify content-type in request?

Content-Type: application/json

Here the request generated by AJAX.NET Beta 2 proxy, see 'js' before method name:

POST /Source/service.asmx/js/UpdateChat HTTP/1.1
Host: localhost:1123
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 Firefox/1.5.0.8
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Proxy-Connection: keep-alive
Content-Type: application/json
Content-Length: 50
Cookie: ASP.NET_SessionId=qpspnn45mgxzlp20xdj0dvng; .SLCVISITOR=200529225
Pragma: no-cache
Cache-Control: no-cache

{"a":246144119,"v":200529225,"n":18,"z":-1,"m":[]}

Thankfomine for providing the answer.

Best Regards


You can use theNewtonsoft.Json libary。

like this:

[WebMethod]
[ScriptMethod]
public string GetData()
{
XmlDataDocument doc =new System.Xml.XmlDataDocument();
doc.LoadXml("/test.xml");

using (StringWriter sw =new StringWriter())
{
using (JsonWriter jsonWriter =new JsonWriter(sw))
{
jsonWriter.Formatting = Newtonsoft.Json.Formatting.Indented;

JsonSerializer jsonSerializer =new JsonSerializer();
jsonSerializer.Converters.Add(new XmlNodeConverter());

jsonSerializer.Serialize(jsonWriter, doc);
}
return sw.ToString();
}

}

Returning web service result from calling function in javascript (Atlas)

When using Atlas is there a way that I can call a web service method and have the result returned from the calling function. I understand that Atlas works asynchronously and therefore uses callback functions but I need the calling function to return the result somehow.

I tried something similar to the following but it didn't work. It seems to be that the global variable only gets updated once the calling function completes.

var getResult;
function LMSGetValue(param) {
// Note that the LMSAPI is setup with a ScriptManager
LMSAPI.LMSGetValue(param,LMSGetValueComplete);
pause(1000);// helper function that pauses by # millisecs
return getResult;
}
function LMSGetValueComplete(param) {
getResult = param;
}

The reason that I have to return the result from the calling function is that the javascript that calls the function (which is located in a iframe) follows a strict specification called SCORM which is used for building sharable elearning content and learning management systems (LMS). The learning content in the iframe calls the LMSGetValue function to get the data from the LMS and expects a return value.

Any help or suggestions on how I might be able make this scenario work would be grately appreciated as I really am quite stuck.

Unfortunately there is no current support for synchronous webservice calls, you cannot return a value from your method directly, the results are only available thru your callback.