I have a call to a method via ajax async:true, but the returned value is not displayed.
$('.loading').show();
$.ajax({
type: "POST",
url: "/client/owedasync/",
data: "client="+id,
async: true,
success: function(t){
alert(t);
$('.loading').hide();
$("#sum_worhhoursowed").html(t+" hours owed");
}
});
if changed to false, it will display the value.
in firebug i can see the response value but not on the page when async: true.
Uh, sorry. It works, but i used FF4b for testing and firebug 1.6x.0b3 with known problems with ajax & FF4b. Disabled the Console everything is back to normal.
Related
In the page_load of page A I Server.Transfer to Page B (Server.Transfer("B.aspx");)
Then on page B I have a simple html button that has the onclick="ajaxFunction();";
function ajaxFuntion()
{
$.ajax({
type: "POST",
url: "B.aspx/MyPageMethod",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
cache: false
});
}
I get ajax error "Method not Found"
When I use Repsonse.Redirect instead of Server.Transfer, it works.
But I need to use Server.transfer. Is there a fix here?
Thx
I think it's because B.aspx renders in the context of A.aspx, and so it's not B.aspx you are currently in, it's A.aspx, as far as the browser is concerned. You can try A.aspx/MyPageMethod and see if it will work...
I am trying to pass extra parameters through to my ashx when using Jquery UI auto complete.
I have seen lots of examples and have spent ages fiddling but I can't get mine to work.
I have two auto complete textboxes, what ever is entered in the first one needs to narrow down the search for the second one.
On my first autocomplete textbox all works fine and the ID that is returned is set to a hidden field.
$("#<%=txtSearch1.ClientID%>").autocomplete('/Search1.ashx');
$('#<%=txtSearch1.ClientID%>').result(function (event, data, formatted)
{
if (data) {
var id = data[1];
$("#<%=hdnSearched1.ClientID%>").val(id);
}
});
I want to use the value of the hidden field along with the value the user enters into the second textbox to do the search for the second auto complete
I first tried this:
$("#<%=txtSearch2.ClientID%>").autocomplete('/Search2.ashx',{
extraParams: { "Id": $("#<%=hdnSearched1.ClientID%>").val() }});
This fired my ashx but the Id in the extraparams was blank. A bit of googling told me this was because it was set when the page loaded so the value for the extra param was set before I set the value of the hidden field.
I did a bit more fiddling and searching and came up with something like this which a lot of people seem to be using.
$('#<%=this.txtSearch2.ClientID %>').autocomplete({
source: function (request, response)
{
$.ajax({
url: '/Search2.ashx',
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
data: {
term: request.term,
sId: $("#<%=hdnSearched1.ClientID%>").val()
},
success: function (data)
{
response(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown)
{
alert(textStatus);
}
});
}
});
The problem is this doesn't even fire the ashx! I have been fiddling about with this for ages, following example after example but I can't seem to work what I am doing wrong!
I'm sure it must be obvious!
Can anyone help?
I want to display a circular progress indicator using jquery in asp.net when textbox textchange event occurs. When user enters some value in a textbox and textchange event occurs or when user loses the focus on that textbox, system checks values in databases. I want to give user a progress indicator type when query is in progress.
How can I accomplish this with jquery?
Code here:
$("#Txturl").blur(function() {
$.ajax({
type: "POST",
url: "Default.aspx/Getvalue",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function(msg) {
///to to do here? i ve no idea;
}
});
return false;
});
This is relatively straightforward. You would start by creating the animated GIF for your indicator (or download a freely available one) and add it to your site. Then in your Javascript, you would add something closely resembling the following:
$('#yourTextBox').change(
function(){
$("#yourProgressImg").show();
$.ajax({
type : "get",
url : <your request uri>,
success: <what to do if it comes back happy>
fail: <what to do if it fails>
complete: function(){ $("#yourProgressImg").hide(); }
});
}
);
The complete functionality of the $.ajax() function is here: http://api.jquery.com/jQuery.ajax/
Not sure how every other site does it, but I would show an animated GIF on the textchange event and hide it in the AJAX success (or failure) function.
Have a hidden div with your animated GIF.
<style>.hidden { display: none; }</style>
<div class="hidden"><img src="spinner.gif" /></div>
Then show it on change and hide it in the success or error callback.
$('#mytextbox').change(function(){
$('#divwithGIF').show();
$.ajax({
type: 'POST',
url: 'Default.aspx/Getvalue',
data: '{}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: true,
complete: function(msg){
$('#divwithGIF').hide();
};
});
});
Repeat for the blur() event.
See my answer on this one: jquery submit and loading gif for an example of how you can construct a global (on the page) event monitor for ajax to display an animated gif as you describe. You can customize this as you wish for your events.
I have a gridview control with delete asp:ImageButton for each row of the grid. What I would like is for a jquery dialog to pop up when a user clicks the delete button to ask if they are sure they want to delete it.
So far I have the dialog coming up just fine, Ive got buttons on that dialog and I can make the buttons call server side methods but its getting the dialog to know the ID of the row that the user has selected and then passing that to the server side code.
The button in the page row is currently just an 'a' tag with the id 'dialog_link'. The jquery on the page looks like this:
$("button").button();
$("#DeleteButton").click(function () {
$.ajax({
type: "POST",
url: "ManageUsers.aspx/DeleteUser",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// Replace the div's content with the page method's return.
$("#DeleteButton").text(msg.d);
}
});
});
// Dialog
$('#dialog').dialog({
autoOpen: false,
width: 400,
modal: true,
bgiframe: true
});
// Dialog Link
$('#dialog_link').click(function () {
$('#dialog').dialog('open');
return false;
});
The dialog itself is just a set of 'div' tags.
Ive thought of lots of different ways of doing this (parameter passing, session variable etc...) but cant figure out how to get any of them working.
Any ideas are most welcome
As always, thanks in advance to those who contribute.
I've recently done something exactly the same at work - confirmation of a delete item. I solved it by using the Data http://docs.jquery.com/Data method to store the value I wanted to pass along.
So for example my delete links had the following:
Delete
Then monitor all clicks on for class "delete", when this happens set the data on the dialog:
$("#dialog").data("id", $(this).attr("id"));
Which will then be accessible when you're in your dialog.
$("#dialog-confirm").dialog({
resizable: false,
height:140,
modal: true,
buttons: {
'Delete': function() {
alert($(this).data('id'));
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
}
});
Hope this helps, shout if it's not clear.
I want to refresh only a single part of my page not the whole.
How ?
I wouldn't recommend Update Panel but you can use jQuery $.load() method which is pretty slick. Once you start using it, it helps you a lot.
So use Ajax... long story short.
Edit :
Maybe this article help as well :
Why Update Panels are Dangerous :
http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/
In web forms you can use the update panel
See here for example
You can also use JQuery although it depends on what you are trying to do and to what complexity.
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "YourPage.aspx/apply",
dataType: "json",
data: json.stringify(""),
success: function (result) {
alert(result);
// window.location.href = "ClubCreation.aspx";
},
Error: function () {
alert('error');
}
});
[HttpPost]
public string apply()
{
return "Hi";
}
You can use Ajax to solve your problem this code will help you