Javascript - $.ajax Json Method Does Not Hit The Web Method?
Sep 22, 2010
When this function is hit , it does not call my function in code behind? Why could it be doing this? How can I fix this error.
$(document).ready(function() {
$('[id$=btn_Update]').click(function() {
var reten = $('[id$=txt_Reten]').val();
var i=0;
var selectValues = "";
var ProdID = new Array();
$("#lst_ProdId option").each(function() {
selectValues = selectValues + $(this).text() + ",";
ProdID[i] = $(this).text();
i++;
});
for(var j=0; j < ProdID.length;j++)
{
// alert(ProdID[j]);
}
var params = "{'ProdID':'" + ProdID + "','RetenP':'" + reten + "'}";
$.ajax({
type: "POST",
url: "/ProductPricing/Products/RetenPeriod.aspx/UpdateRetenPeriod",
data: params,
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function(result) {
alert("sucess");
},
error:function(e) {
alert(e.statusText);
// if(errorThrown != null)
// alert(textStatus+ ":"+errorThrown);
// else
// alert("fail");
}
});
return false;
});
return false;
});
This is my webmethod in code behind:
[WebMethod]
public static bool UpdateRetenPeriod(string[] ProdID,string RetenP)
{
for (int i = 0; i < ProdID.Length; i++)
{
update(ProdID[i],RetenP);
}
return true;
}
View 3 Replies
Similar Messages:
Aug 26, 2010
I have an application that has JS calling ASMX files to do asyncronous requests, using ASP.NET AJAX.
The problem is that I use always the same "onError" function, and now I don't know how to identify the method that rised the error, and it is giving me a lot of problems to debug errors. The parameter "data" of the onError method does not give enough information, for
example:
en System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
en System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)
en System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)
en System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)
en System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams)
en System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)
en System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)
en System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)
Is there any way to know the webmethod that raised the error?
View 1 Replies
Dec 21, 2010
I am creating one Json array object and trying to pass it in MVC controller action method but i am getting null paramerter; as per my knowledge json only maps .net primitive datatypes.... so it assign null value.
Note: when i have look at request object i found that there are three parameter of created array. But how to get that value as parameter of function?
View 2 Replies
Feb 4, 2010
The ideal goal is to consume .asmx web service using jQuery like this
[Code]....
View 2 Replies
Jun 9, 2010
function createSuccess(context) {
$get("result").innerHTML = context.get_data();
}
<% using (Ajax.BeginForm(new AjaxOptions {OnSuccess="createSuccess"}))
{%>
What does context holds in the createsuccess method? data return by controller? How do we return json data in the createsucess if so
View 1 Replies
May 12, 2010
I want execute below callback() method after completion of document.getElementById('btnDownload').click(); method . Now callback()executing immediatly. I want wait "Click()" process done then Execute callback(); method.
function LoadPopup() {
// find the popup behavior
this._popup = $find('mdlPopup');
// show the popup
this._popup.show();
// synchronously run the server side validation ...
document.getElementById('btnDownload').click();
callback();
}
function callback() {
this._popup = $find('mdlPopup');
// hide the popup
this._popup.hide();
alert("hi");
}
View 2 Replies
Jan 25, 2011
I have a web method in my code behind:
[System.Web.Services.WebMethod]
public static string GetStateData(string state)
{
//this is where i want to call a javascript method "GetItems"
}
I have a javascript method that retrieves some values for me and I want to get use one of those values in my web method
function GetItems() {
var variable1= $("#<%=Item1.ClientID %> input:checked");
var variable2= $("#<%=Item2.ClientID %>").val();
return [variable1.text(), variable2.val(), variable2];}
I've searched for ways to call the javascript method from the web method but every time my search results in how to call a web method from javascript.
I did find this but it was done from the code-behind of a silverlight project and when I tried adding the correct reference to my code-behind it wasn't there
var result = HtmlPage.Window.Invoke("GetItems"); Is there a reference I'm missing?
View 2 Replies
Nov 1, 2010
i have a web service that i use for the AutoCompleteExtender, let the below code show you what i'm trying to do: [Code]....
this method is called, and when it calls the method inside the Patients Class, it gets lost. does that mean that i can't use 3-tier approach with web methods?
View 2 Replies
Mar 26, 2016
$("#Name").on("blur", function() {
if (Name != "" && Name != null) {
var options = {
type: "POST",
url: "ApplyNow.aspx/CheckName",
[code]...
how to use the value of 'duplicate' in btnsunmit_click() from webmethod.
View 1 Replies
Mar 9, 2011
I have a tricky problem. I am in a situation where I need to use a method defined in a .cs file from a javascript function. The problem is we are using .NET 1.1 and AJAX cannot be used for the application.
Also, I will need to pass a string from the javascript to the server side method. The page where I am implementing the javascript is a .as
I have tried doing a post back and creating a RaisePostBack event handler method (both in the .aspx page and the .ascx user control) but no luck.
The javascript is called from a span's onclick event. The javascript function's input parameter would be a string which I will need to use to instantiate an Attachment.
I created a method which instantiates an Attachment using a string and calls the corresponding Delete() method for the Attachment object.
Now, I will need to pass the string from javascript function to the method I have created. I cannot use PageMethods.
The Javascript function is like:
[code]....
View 3 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
Jul 22, 2010
I'm trying to implement the cascading dropdown from the toolkit. I need to get the count in a sub category dropdown, if it's zero then I turn off the visibility of the sub category.
If I use the javascript OnChange event then my script fires before the web method, so I need to know how to fire my script AFTER the web method has fired.
Below is my code and the order I need it to fire.
[WebMethod]
public CascadingDropDownNameValue[] GetSubCats1(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int CategoryID;
[Code]....
View 10 Replies
Apr 13, 2010
I am creating an Asp.net web site which will support dynamic data. When I am creating a dynamic web site from Scratch (from template in VS) all is working fine. But when I am trying to add dynamic entity (.edmx) file and running the application I am getting following error
"The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'. "
View 2 Replies
Nov 16, 2010
i use JSon to return allot of results when building a website, but find myself writing a a lot of code like this:
[Code]....
and then simply call this function with whatever IEnumerable results i have my question is would i be on the right lines here, what would be the best possible way to do this as it makes no sense to be writing in MVC and OOP but to keep rewriting code to just FROM ?
View 5 Replies
Feb 15, 2011
[Code]....
If I use $get, it does work as the expected functionality for $get. It is only $find that does not work.
Can anyone explain the problem?
View 5 Replies
Oct 6, 2010
How can I upload files asynchronously with JQuery?
I have a file upload field, after the image was selected, i make a jquery ajax post to an aspx page's page method. My question is, how can I pass that image via jquery? When I do $(this).val() it only gets the file name. I want to pass the image object itself.
View 2 Replies
Aug 11, 2010
I got XYZ page which got few divs inside of himin 1 of the divs there in an updatepaneland in another there are buttons which being inserted into the page using javascriptWhat I want to do is once a button is clicked, it would invoke a method using javascript in the server which would update the updatepanel
View 2 Replies
Oct 10, 2010
I have a JSON object in javascript
it is a collection of Object
How can I pass this object to a controller if i am submitting the form like
$('#myform').submit();
what object type should i give for the parameter to accept this Json
View 5 Replies
Apr 20, 2010
I get this error "The server method xxx timed out." calling a WebService that internally does a hard query to the database, and takes some time. I use this method to change the webservice timeout, but it does not seems to do anything (the timeout errors appears in less than a second).
MyService.set_timeout(100000);
View 2 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
Nov 15, 2010
I have a usercontrol that wprks fine as along as one instance is on a pageut as soon as i have two instances of it nothing works. I figured out that it could be the pageload function that adds handler for keydown and other that is the cause.As each instance is reproducing the same javascript in the viewsource.So can you tell me how can i make the usercontrol that it can have multiple nstances that have their own javascript pageload
View 4 Replies
Apr 3, 2010
How to call a method on a server side from JSON. Below is the code I am using
SERVER SIDE:
[Code]....
Now I want that on button click, I would call the function at the client side [JSON], which pass the textbox value to the function.
View 2 Replies
Sep 10, 2010
I have problem with JSON, MapRoute. If I click on "save" I always get Page / Index Page instead of / SendForm. I dont know why, in javascript it says url: '/ page / sendform'. But the problem is at Global.asax.cs,
routes.MapRoute("Default",
"{controller}/{action}/{url}",
new { controller = "Page", action = "Index", url = UrlParameter.Optional });
But there is still problem at the url, which shows Controller, Action that I dont want to .. I have a url / lang / seo-url /. How can I achieve by clicking on the Save, it should call SendForm method instead of Index ..
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("page",
"{lang}/{url}",
new { controller = "Page", action = "Index", lang = "cz", url = UrlParameter.Optional });
routes.MapRoute("Default",
"{controller}/{action}/{url}",
new { controller = "Page", action = "Index", url = UrlParameter.Optional });
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());
}
}
Index.aspx
<script type="text/javascript">
$(function () {
$("#personCreate").click(function () {
var person = getPerson();
// poor man's validation
if (person == null) {
alert("Specify a name please!");
return;
}
var json = $.toJSON(person);
$.ajax({
url: '/page/sendform',
type: 'POST',
dataType: 'json',
data: json,
contentType: 'application/json; charset=utf-8',
success: function (data) {
// get the result and do some magic with it
var message = data.Message;
$("#resultMessage").html(message);
}
});
});
});
function getPerson() {
var name = "Ruda";
var age = "18";
// poor man's validation
return (name == "") ? null : { Name: name, Age: age };
}
</script>
<input type="submit" value="Save" id="personCreate" />
PageCollector.cs
public class PageController : Controller
{
//
// GET: /Page/
public ActionResult Index(string lang, string url)
{
switch(url)
{
case "anglictina":
return View("~/Views/English/Index.aspx");
case "nemcina":
return View("~/Views/German/Index.aspx");
case "prihlaska":
return View("~/Views/Application/Index.aspx");
case "galerie":
return View("~/Views/Galerie/Index.aspx");
case "kontakt":
return View("~/Views/Contact/Index.aspx");
default:
return View("~/Views/English/Index.aspx");
}
}
[HttpPost]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public JsonResult SendForm(string name, string age)
{
return Json(string.Format("Message: '{0}'", name));
}
}
View 2 Replies
Mar 14, 2011
I am trying to return some data as json from an action method.
I have an employee object that looks like this:
public class Employee
{
public int EmployeeID {get; set;}
public string FirstName {get; set;}
public string LastName {get; set;}
//Other irrelevant properties
}
Then I have a view model as follows
public Class EmployeeViewModel
{
public Employee Supervisor{get; set;}
public List<EmployeeViewModel> Employees
}
I need to return a json object that looks exactly like this:
{id: 1, name: John, children: [
{id: 1, name: Joe, children: []},
{id: 1, name: Rob, children: []}
]}
For now I only need to go to the second level as above, returning and supervisor and their staff members beneath them.
How would I go about returning this in my action method(I have the viewModel object hydrated already I just need to return it as json). My problem so far has been that the children property does not get populated.
View 1 Replies
Sep 24, 2010
I added the extender and when i tried to add the method this message poped up; Cannot create page method "GetCompletionList" because no Code Behind or codefile was found.
View 4 Replies