Kill A Javascript Async Call To A .net Webservice?
Jun 14, 2010
My javascript code is calling a asp.net webservice, so i have a call to the webservice something like this:MyWebservice.GetData(param, ResponseReceived, ResponseTimeOut, ResponseError);When the webservice returns data, ResponseReceived method is called.However sometimes the user might navigate to another url before the webservice call actually returns, in such a scenario FireFox throws an Error saying 'An error occured oricessubg the request. The server method GetData failed'So my question is how can i kill the async call when the user navigates to another page or makes another request to the webservice? I know in a normal XMLHttpRequest i could have called Abort method, but not sure how to make it work with the above webservice proxy.
View 2 Replies
Similar Messages:
Nov 5, 2010
I'm doing a project in asp.net with a web services. My web services and my asp.net project is separate and my asp.net projet have a reference of my web services. i'm using visual studio 2008 framework 3.5 and my service web is in vb.net. i want to call the web methods of my web services in javascript my script manager is declared
<asp:ScriptManager runat="server" ID="scriptManager" EnablePageMethods="true" >
<Services>
<asp:ServiceReference path="http://localhost:2931/ServiceCompas.asmx"/>
</Services>
</asp:ScriptManager>
the javascript fuctions
<script type="text/javascript">
function test() {
alert('test');
Service1.Liste_Carte(Onsucced);
}
function Onsucced(resultat) {
alert('je suis passée');
}
</script>
service1 is the class of my Webservice and i call the function test with my button <input name="btnRecherche" class="btnRechercher" type="button" value="Rechercher un emplacement" onclick="test()" /> the problem is : JavaScript say Service1 is not defined but why .... What's the problem ? I've checked many forums and videos every body did it
sorry for the french variable
View 3 Replies
Jan 11, 2011
all My web app is calling webservice which resides in same virtuall directory as web app . In this scenario i have a javascript function like this which works perfectly.
[Code]....
View 2 Replies
Jan 28, 2011
I'm calling a webservice using jQuery with .ajaxHere are the data parameters for the call:
var parameters = "{'Titre':'" + Titre + "','Description':'" + Description + "','Contact':'" + Contact + "','VilleId':'" + VilleId + "','QuartierId':'" + QuartierId + "','UserId':'" + UserId + "'}";
It works fine. But when parameters Description or Titre contain the ' character , no call!!!
Does anyone have an idea how can i make it work even with apostrophe character in Titre and/or Description?
View 4 Replies
Mar 10, 2010
I am trying to call a webservice method fom javascript.Every thing goes fine. But,problem is that, I can't return any value from the function.
View 3 Replies
May 13, 2010
Configuration : Windows Vista,VS 2005,Ajax v1.0.61025 My Html Page
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">
function fnCall()
{
try
{
var ans= Sim.Service.HelloWorld(OnMethodSucceeded, OnMethodFailed);
}
catch(e)
{
alert(e.message);
}
}
function OnMethodSucceeded(result)
{
alert('a');
}
function OnMethodFailed(result)
{
alert('b');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" ><Services>
<asp:ServiceReference Path="http://localhost/ajaxtest/service.asmx" /></Services>
</asp:ScriptManager>
<div><input id="Button1" type="button" value="button" onclick="fnCall();" /></div>
</form>
</body>
</html>
Web Service CS.
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
namespace Sim
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Service : System.Web.Services.WebService
{
public Service()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod,ScriptMethod(UseHttpGet=true)]
public string HelloWorld()
{
return "Hello World";
}
}
}
But i am getting Sim is not defined. Error. post ur comments. I have reviewed most of the forums. I am not able to clear
View 13 Replies
Mar 2, 2010
I am calling a web service via Javascript. I tried it first in a web page that does not have a Masterpage and it worked perfectly. Then I moved everything over to a web page that does use a Masterpage, and I get a "Microsoft JScript runtime error: Object required" on the javascript statement that calls the web service. My javascript statements look like so:
[Code]....
The web service looks like:
[Code]....
The page source is:
[Code]....
View 5 Replies
Jan 8, 2011
I have a web user control. That I load dynamicaly inside a modalpopup window using dynamic populate extender. User control has a external javascript file linked to it. Problem: I cannot make call to webservice method from this external javascript file. When I make a call -- servicename.methodname() I get servicename not defined error.
View 2 Replies
Mar 21, 2011
Is there a simple way to turn off form submit behaviour of the page when ENTER is pressed while I am focused to textbox? What I want to achieve is to call a web-service without submiting the page when ENTER is pressed in a specific textbox in my aspx page?
View 1 Replies
Nov 23, 2010
Pinging back to a webservice in ajax from the client keeps the user's session alive, I don't want this to happen. More extensive summary For a website we're developing, we need the client to ping back (in js) to a webservice (ASMX) on the server (IIS7.5). This happens to let the server know that the user is still on the site, and hasn't browsed away to another site. This is as our customer wants to let users lock records, but if they browse away to other sites, then let other people take over those locked records. Perhaps the distinction between the client being on the site but inactive and on another site seems unimportant, but that's kinda irrelevant, I don't get to write the UI spec, I just have to make it work.
My problem is this, the ping stops the user from being timed out on the server through the standard forms authentication timeout mechanism. Not surprising as there is that 30 second ping in the background keeping the session alive. Even though we want to know if the user is still on the site, we want the normal forms authentication timeout mechanism to be honoured. I thought I might be able to fix this by removing the ASP.NET_SessionId and .ASPXAUTH cookies in the XMLHttpRequest that is the server ping, but I can't figure out how to do this. This is how my web service & method are defined:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class PingWS : WebService
{
[WebMethod]
public void SessionActive(string sessionID)
{
// does stuff here
}
This is how I'm calling it in js (request is over HTTPS, :
$.ajax({
type: "POST",
url: "PingWS.asmx/SessionActive",
data: 'sessionID=' + aspSessionID + '}',
beforeSend: function (xhr) {
xhr.setRequestHeader('Cookie', '');
xhr.setRequestHeader('Cookie', 'ASP.NET_SessionId=aaa; .ASPXAUTH=bbb;');
},
dataType: "json"
});
I was trying with the setRequestHeader, but that just appends to the header rather than overwrites the header, and IIS is happy to ignore that junk I added. I'm thinking maybe I should be trying to do this at the server end, someone take PingWS.asmx out of the loop so that it doesn't keep the session active, but I'm not sure how to do this. Although the title of the question is focused on clearing the cookie in the header, I'd be super happy if anyone points out that I'm being really stupid and there is actually a much better way of trying to do what I'm doing.
I'm thinking at this stage maybe I need to add something to the webmethod that says how long this particular page has been inactive, and use that knowledge to timeout manually. That actually sounds pretty easy, so I think I'll do that for now. I'm still convinced that there must be an easy way to do what I originally wanted to do though. Update I'm thinking I'm pretty screwed in terms of cookie manipulation here as both the .ASPXAUTH and ASP.NETSessionId cookie are HttpOnly, which means the browser takes them out of your hands, you can't access them via the document.cookies object. So I would say that leaves me with:
Updating my SessionAlive webmethod to track each request so I can tell how long the user has been sitting idle on a page and timeout if needs be Marking the .asmx page somehow on the server end so that it's taken out of the normal authentication/session tracking flow I know how to do 1. so I'll start there but 2. seems much cleaner to me.
View 3 Replies
Aug 16, 2010
I was created webservice which has a Method:
[Code]....
Then, in my aspx page, i call that method in javascript, but i get a Exception message is "Authentication Failed", code below:
[Code]....
How to resolve this problem?
View 3 Replies
May 13, 2010
I have a simple web page in ASP.NET / C#. Currently to fully render the data I require calling a block of code that runs on background threads and can take multiple minutes to complete. I've got it to the point (using the async attribute on the page declaration) to execute and return fine with the html once it's done. What I'd like it to do is allow me to return immediately with a 'loading page' of some sort and then have that page be updated when the background work has been completed. Right now I get nothing on the page while the background work is being processed.
View 3 Replies
Feb 23, 2011
I want to make an async call to the server when an achor tag is clicked and then have the browser advance to the href without waiting for the async call to return a result. I am using System.Web.UI.ICallbackEventHandler. My server code is not executing. The server code only executes if the GetCallbackEventReference call specifies a clientscript value which means the page has to wait before advancing. What am i doing wrong?
My client code is:
<script type="text/javascript">
function ReceiveServerData(arg, context) {
}
function DoAsyncTask(arg)
{
CallServer(arg, '');
return false;
}
</script>
View 3 Replies
Nov 11, 2010
For example, I am using wenclient.DownloadfileAsync to download a file asynchronously.
In the DownloadFileCompleted event handler, I can check if I have any exception or not by using AsyncCompletedEventArgs.Error property.
If I re-throw this exception, however my executable is stopping running immediately.
I am wondering how to handle this kind of exeception? How to pass this exception back to the
calling thread?
View 1 Replies
Mar 15, 2010
Since data saving is a time consuming, I would like to call data saving method using Ajax and that too Async what i mean is as soon as the user click submit button it just display the confirmation page and data saving bit keeps going on in the background.
Is this possible using Ajax tool kit?
View 3 Replies
Jan 11, 2010
In our application we have a scenario where we need to display a panel using modalpopupextender after performing an async call on the server. We were using the Show method for displaying the popup. It used to work fine without any async call. But when an async call was introduced during the request processing the popup is not getting displayed.
View 7 Replies
Mar 14, 2010
How do force full page rendering in async call process?
[Code]....
View 4 Replies
Feb 4, 2011
I have the following code on my website:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="myButton_btn" eventname="Click" />
</Triggers>
<ContentTemplate>........
The javascript is running everytime I click the button. However, even though my subroutine updates the session variable after clicking the button, I always get the same alert. In other words, the same javascript is run after postback, and it is not updated. I am positive that the session variable IS being changed.
View 2 Replies
Apr 27, 2010
I am creating a ASP.Net server control to manage locations. The control is a composite control containing several text-boxes, labels, and a link button. I use the AJAX Control Toolkit to provide a modal popup which contains a Bing map. All the Javascript is in its own file and used as an embedded web resource.
The link button is what opens the modal popup. It also needs to call a Javascript function that initializes the Bing map (onclick = "GetMap();"). There are instances when this server control is placed within an Update Panel (and there is no way to avoid this). When in an Update Panel the link button loses its onclick event. I understand that this is because during an async postback the portion of the DOM that defines the content of the Update Panel is thrown out and reinitialized, resulting in the event breaking. When the control is not in an Update Panel everything works as intended.
I have tried registering events on Page.Load and Page.Init, like so:
[Code]....
I have also tried flat out writing the function call to the page:
[Code]....
I have put breakpoints on the lines inside each delegate and they do not get hit. I am not aware of any special way to register events of a composite control's child control or the Page.Load/Page.Init events when being done inside a server control. Is there some special way to register these events? (Note: Both those code blocks above are in my CreateChildControls() method)
Below is the GetMap() Javascript function. As you can see it is pretty straight forward.
[Code]....
View 3 Replies
Sep 30, 2010
I have multiple update panels with various asp buttons on a single page. I want to disable the buttons which caused the postback in update panel untill it completes.
Is there a way to avoid using a third party control for this? through JQuery or any other method ?
View 2 Replies
Jan 11, 2010
I have to call a webservice published in the same website the caller aspx is. When I try to "Add a Web Reference" the editor does not show the webservice methods from the generated namespace. Do I have to use the "Add Web Reference" or is there another way because the webservice is in the same website? Visual Studio 2005, C#
View 3 Replies
Feb 8, 2011
I have two solutions in .net (solution "A" and solution "B") which both have web services. I want to call a web service method in solution "B" from solution "A". I am very new to C#.
View 3 Replies
Sep 14, 2011
I have a web app that makes a call to a webservice, and it is causing a ThreadAbortException. Why is this? This does not happen when calling the webservice in a windows form application.
View 1 Replies
Sep 13, 2010
how to call web service with jquery in asp.net with param value
View 7 Replies
Jan 15, 2010
I need to make a call to a json webservice from C# Asp.net. The service returns a json object and the json data that the webservice wants look like this:
"data" : "my data"
This is what I've come up with but I can't understand how I add the data to my request and send it and then parse the json data that I get back.
string data = "test";
Uri address = new Uri("http://localhost/Service.svc/json");
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
request.Method = "POST";
request.ContentType = "application/json; charset=utf-8";
string postData = "{"data":"" + data + ""}";
How can I add my json data to my request and then parse the response?
View 1 Replies