0

I have a page method:

var test = "<?xml version='1.0'?><query><drawioIan>This is Ians XML</drawioIan></query>";
                PageMethods.GetDocument(encodeURI(test), onSuccess, onFailure);
                function onSuccess(result) {
                    debugger;
                    //XML returned, so need to drill into it.
                    alert(result.firstChild.childNodes[0].innerHTML);
                }
                function onFailure(error) {
                    debugger;
                    alert(error);
                }

That is suppoused to call a webmethod:

[WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Xml, UseHttpGet = true, XmlSerializeString = true)]
    public static System.Xml.XmlDocument GetDocument(string svg)
    {
        string test = HttpUtility.UrlDecode(svg);
        //Response Is sent back as xml, you might be able to send back json instead - might be handier.
        System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
        xmlDoc.LoadXml("<root><item>Hello World</item></root>");
        return xmlDoc;
    }

The webmethod does not get called but I am receiving a status code 200 enter image description here

Retuned is the whole html page: enter image description here

The breakpoint on the webmethod does not get triggered either. Does anyone have any idea what the issue may be?

EDIT: WebMetho gets skipped but still comes back with onSuccess(): enter image description here

Tim Daiber
  • 348
  • 3
  • 6
  • 19
  • clean and build the solution, then run again and then call the api method – Vivek Nuna Jun 23 '20 at 11:44
  • @viveknuna Cleaned and build the solution and called the method, the issue is the same. – Tim Daiber Jun 23 '20 at 11:47
  • 2
    Breakpoint showing red or hollow circle?, are you using visual studio? If yes then which version? and please make sure you are running in debug mode not release mode\ – Vivek Nuna Jun 23 '20 at 11:49
  • @viveknuna I am using visual studio 2019, the breakpoint is red so it should be reachable. It's a webforms project build on .NET framework 4.7.2 – Tim Daiber Jun 23 '20 at 11:54
  • add this on the line where you are setting the breakpoint `System.Diagnostics.Debugger.Break` and then run and then see – Vivek Nuna Jun 23 '20 at 11:54
  • @viveknuna I added this line to the WebMehtod but the web method never gets called and the breakpoints are not getting hit. (I am running in debug mode). It scrips the webmethod and goes straight on to onSuccess()-> debugger. Adding a picture to my question. – Tim Daiber Jun 23 '20 at 12:07
  • Do you have a script manager with page methods enabled? – wazz Jul 06 '20 at 09:59
  • Does this answer your question? [ASP.NET PageMethod onSuccess function returns a HTML String](https://stackoverflow.com/questions/37670600/asp-net-pagemethod-onsuccess-function-returns-a-html-string) – AvahW Nov 30 '21 at 12:13

0 Answers0