Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

I have a jQuery method that calls a web method. The jQuery method only executes one time but the web method executes multiple times for chrome and IE. But only once for Firefox.

We used Jquery Ajax[$.Ajax()] to call WebMethod.

We have traced this using debug and Fiddler.Let us know how to solve the issue for cross browser.

Thanks in Advance.
Posted
Comments
ZurdoDev 2-Jan-15 17:26pm    
It works cross browser so you must have something else going on.
Nilendra Nath 21-Jan-15 3:19am    
Can you please share the code which is calling web method?

1 solution

Hi Nilendra,

Please find the below piece of code from my application.


Ajax Call:
  else if ($("#iFrameHtmlImage")[0] != null) {
                                $.ajax({
                                    type: "POST",
                                    url: "Default.aspx/ReplaceHTMLFile",
                                    data: JSON.stringify({ "content": str, "name": $("#iFrameHtmlImage")[0].src }),
                                    contentType: "application/json; charset=utf-8",
                                    dataType: "json",
                                    processData: false,
                                    success: function (msg) {
                                        refreshMainHtml($("#iFrameHtmlImage")[0].src);
                                        document.getElementById('iFrameHtmlImage').contentDocument.location.reload(true);
                                        lblText.Set("Text", undefined);
                                    },
                                    error: function (msg, status) {
                                        if (status === "error") {
                                        }
                                    }
                                });

                            }

Web method:
  [WebMethod]
        public static string ReplaceHTMLFile(string content, string name)
        {
            try
            {
                string fileTempLocation = ConfigurationManager.AppSettings["TemporaryHtmlFilePath"];
                string htmlHedder = "<!DOCTYPE html> \n <html lang='en'> \n";
                StringBuilder sbContent = new StringBuilder(content);
                sbContent = sbContent.Replace("<html>", htmlHedder);
                var uri = new Uri(name);
                var path = Path.GetFileName(uri.AbsolutePath);
                StreamWriter tw = new StreamWriter(fileTempLocation + path, false, Encoding.Default, 0x640000);
                tw.WriteLine(sbContent.ToString());
                tw.Close();
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, "DesignS");
                HttpContext.Current.Session["DesignSErrMsg"] = ex.Message;
            }
            return "";
        }


Request you to please provide the solution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900