JQuery :: Get JSON Call To MVC Controller Not Returning Data

Nov 25, 2010

This is probably something simple. The following JQuery call is executing and calling the controller. The controller is executing correctly. I used the sample data that's commented out to verify that the templates were working also. However, the success function is not executing in the browser. Any thoughts or other ways I can debug this?

<script type="text/javascript">$(document).ready( function(){ alert("Here"); @* var myData = [ {first: "Jane", last: "Doe"}, {first: "John", last: "Doe"} ]; *@ $.getJSON( "/User/Filter",function(myData){ $("#myDataTemplate").tmpl(myData).appendTo("#itemContainer"); } ); alert("there"); }
);</script>
//Controller
public ActionResult Filter() { var myData = this.repository.GetAllUsers(); //return Json(myData); return Json(myData, JsonRequestBehavior.AllowGet);}

View 6 Replies


Similar Messages:

Jquery - Get Json Data In Controller Action?

Feb 9, 2011

I have asp.net mvc application. i want to configure the object in jquery and want to pass it to the the action of controller . where as in my script i am using this for configure data for the ajax call:

[Code]....

it does not calls to action in controller. i think here :

var json = $.toJSON(peform);

is not working as expect. is it need to add any js file to reference ? or mistake in syntax?

View 1 Replies

JQuery :: JSON Data Disappears On Call?

Oct 12, 2010

I have a problem with a AJAX call I do in a application. It's a MVC application (ASP.net c#) with a lot of javascript.

When I do a call from my javascript to a controller (through a ajax call) the call gets to the class and function, but the data isn't there. The data is send in JSON.

I found a few of the same problem but most of the time they used another name voor de parameter then it is in there json.

Here is the code

[Code]....

View 3 Replies

JQuery UI Autocomplete WebService Source Returning JSON?

Nov 29, 2010

I have been trying for two months to get this code working, and I am close, but still confused. I want the JQuery UI Autocomplete function to call an web service which returns JSON data and display that data for selection, and on selection put the selected value into a hidden field.

There are several issues:

1) The autocomplete function is not firing
2) The source: "/AutoSuggest.asmx/DOTFind?" line throws an invalid object exception
3) The service requires two parameters: (string prefixText, int count) - count tells it how many records to return.
4) I am not at all certain that this code will accept JSON data that comes back from the service

Here is the code:

[code]....

View 4 Replies

JQuery :: Returning A Json String From A Webmethod From An Aspx Page?

Nov 27, 2010

My Problem is that i am returning a json string from a webmethod from an aspx page.

I want to create a dynamic html table using that json string but found no solution for that.

Can anyone Provide me the solution to generate html table from json string ?

View 6 Replies

Jquery - WebMethod Returning JSON But The Response Obj In $.ajax() Callback Is Only A String

Mar 8, 2011

public class JsonBuilder
{
private StringBuilder json;
public JsonBuilder()
{
json = new StringBuilder();
}
public JsonBuilder AddObjectType(string className)
{
json.Append(""" + className + "": {");
return this;
}
public JsonBuilder Add(string key, string val)
{
json.AppendFormat(""{0}":"{1}",", key, val);
return this;
}
public JsonBuilder Add(string key, int val)
{
json.AppendFormat(""{0}":{1},", key, val);
return this;
}
public string Serialize()
{
return json.ToString().TrimEnd(new char[] { ',' }) + "}";
}
}

Here is the Web Method [WebMethod]

public static string GetPersonInfo(string pFirstName, string pLastName)
{
var json = new JsonBuilder().AddObjectType("Person");
json.Add("FirstName", "Psuedo" + pFirstName).Add("LastName", "Tally-" + pLastName);
json.Add("Address", "5035 Macleay Rd SE").Add("City", "Salem");
json.Add("State", "Oregon").Add("ZipCode", "97317").Add("Age", 99);
return json.Serialize();
}................

View 1 Replies

MVC :: Using json And Jquery To Send A Form To The Controller?

Nov 21, 2010

i am using json and jquery to send a form to the controller like below, when i click submit validation occers but line is executed even if form is invlid. How can i tell if form validation failed or succeded using javascript?

[Code]....

View 2 Replies

JQuery :: Call C# Function Using Json?

Feb 9, 2011

I have a dropdown box on my aspx page, I would want o pupulate it using jquery's json of calling a method. I do not want to call a webservice method. I have a class, in C# and want to call a method from the class.

View 6 Replies

JQuery :: Make Json Call To Send An Email?

Aug 27, 2010

the aspx:

[Code]....

the jquery :

[Code]....

The problem is that I need to use the text in a text box in my webmethod, and I can't because it's static, this results in a compilation error:

[Code]....

What can I do ?

View 8 Replies

Make A JQuery Ajax Call To A Webservice That Needs To Return JSON

Jun 19, 2010

Actually I am trying to learn jQuery Ajax calls to asp.Net webservices.

I have been trying to call the webmethod below:

[code]....

Do I need to serialize my object in some way before setting the 'data' attribute, so that I can call $.ajax() function?

View 2 Replies

MVC :: Call And Action / Controller From Inside Jquery?

Nov 17, 2010

How do I call and action/controller from inside a jquery function?

View 3 Replies

Jquery - Call Ascx Page From A Controller?

Mar 22, 2011

i have an ascx page and it contain certain methods... on click i want to make a jquery ajax call to the controller and call the ascx page methods..

View 3 Replies

MVC :: How To Call Post Action Controller From View Using Jquery

May 12, 2010

ia ma working on an asp.net mvc 2 app and i have a Users view, displaying all the users of the database. Then, i would like to add the ablility to display "users starting with fisrt name" capabaility on the same view. For this i created a list of all english leters that actually are links (<a href="#">A</a>, etc...)

I managed to handle the click event of each one of the letters and get the corresponding letter via jquery, but i don't know how to call theHttp.Post Users/FindUserByFirstLetterName(string letter) on the click event.

I cannot use the Html.ActionLink<> helper, since it redirects me to the HttpGet controller action.

I also tried using using jqery.Post but i also couldn't manage to call the action.

View 7 Replies

MVC :: To Call Non Ajax HttpGet Controller Action Via Jquery

Jul 6, 2010

i would like to call an HttpGet GetEvents(Datetime dateSelected) controller action each time the user cliks on a date in jquery ui datepicker. I handle the onSelect datepicker event in order to call GetEvents() and refresh the Events page with the events for the selected date. The $.ajax method i use from jquery hits the GetEvents action, but instead of refreshing the page (and the url), i get an ajax result back.

[Code]....

So, how could i just call the HttpGet GetEvents() controller action via jquery, without the use of ajax in order to refresh the page?

View 2 Replies

MVC :: Calling Controller Action Using Jquery Post Ajax Call Abondons Session?

Apr 9, 2010

i have a website where i provicde a link. On clicking the link a controller action method is called to generate a zip file after creation of zip file is done, i show the link to download the zip file by replacing the link to create a zip with the link to download the zip.

the problem is that after zip file creation is over and link is shown, when user clicks on the link to download the zip file, they are sent to login. After providing correct credentials in the login page they are prompted to download the zip file. they sould not be sent to the login page. In the action to generate zip file i haven't abondoned the session or haven't not done anything that abondons the session.

the user should not be sen't to login page after successful creation of zip file user should be able to download the file without login. i search internet on this problem, but i did not find any solution. In one of the blog written by hanselman i found this statement that creates the problem with the session: Is some other thing like an Ajax call or IE's Content Advisor simultaneously hitting the default page or login page and causing a race condition that calls Session.Abandon? (It's happened before!)

so i thought there might be some problem with ajax call that causes the session to expire, but i don't know what is happening? it's like this after users click on the link to create zip file the zip file is created successfully but the session gets expired. this is not what i want. Why does the session has to get expired after making a jquery post call to controller action to create a zip file? i hope u understand the problem.

View 5 Replies

WCF / ASMX :: Windows Communication Foundation Service Returning Xml / Json Data?

Aug 25, 2010

I Need by service contract to return the xml/json result depending on the request type. function which will convert my result set (i am using linq to sql) so that i do not need to create the xml format for the result set by iterating through the table row many times.What is the suitable way to do that.

I need a kind of short cut method which will convert the table data to xml result.Had i been using asp.net mvc i would have been able to generate the xml data by overriding the the ExecuteResult method in the ActionResult and giving Conetnt-Type = "text/xml" as OP.But since i am using Wcf i don't have the controller context(as controller context is the parameter that needs to be passed to Execute Result).

My present code for converting the table data to the xml format is below.

public XDocument UsersLists(string authToken)
{
bool IsAuthenticated = Authenticate(authToken);
XDocument xDoc = new XDocument();
XElement root = new XElement("Users");

[Code]....

I need to eliminate this way of generating xml for each table records.

View 1 Replies

Passing Data From Controller To View Using JSon Object

Mar 4, 2011

I have the following to get the Json abject passed from the controller and populate the various textboxes in the view. However, nothing is happening even though controller is passing a valid Json object. What is wrong with this code?

<script language="javascript" type="text/javascript">
$(document).ready(function() {
var url = '<%=Url.Action("DropDownChange") %>';
$("#vendorID").change(function() {
var selectedID = $(this).val();
if (selectedID != "New Vendor Id") {
//$.post('Url.Action("DropDownChange","Refunds")', function(result) {
$.post(url, { dropdownValue: selectedID }, function(result) {
alert(selectedID);
$("#name").val(result.Name);
$("#city").val(result.City);
$("#contact").val(result.Contact);
$("#address2").val(result.Address2);
$("#address1").val(result.Address1);
$("#state").val(result.State);
$("#zip").val(result.Zip);
});
}
});
});
This is the code in my controller;
public JsonResult DropDownChange(string dropdownValue)
// This action method gets called via an ajax request
{
if (dropdownValue != null && Request.IsAjaxRequest() == true)
{
paymentApplicationRefund =
cPaymentRepository.PayableEntity(dropdownValue);
paymentApplicationRefund.Address1.Trim();
paymentApplicationRefund.Address2.Trim();
paymentApplicationRefund.Name.Trim();
paymentApplicationRefund.City.Trim();
paymentApplicationRefund.Contact.Trim();
paymentApplicationRefund.State.Trim();
paymentApplicationRefund.Zip.Trim();
return Json(paymentApplicationRefund,"application/json");
}
else
{
return null;
}
}

View 3 Replies

Jquery - JSON Can Call Method In .aspx File But Not In .asmx (web Service) File

Jul 3, 2010

I am using JQuery & JSON (POST) to call webmethod. However I can call only webmethod located at aspx file but not in asmx file Below are sample codes

CustomValidate.asmx
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Public Class CustomValidate
Inherits System.Web.Services.WebService
'ACCESS VIA JSON
<System.Web.Services.WebMethod()> _
Public Shared Function AJAX_Test(ByVal date1) As Boolean...
Return True
End Function
End Class
Javascript: JQuery JSON
function isDates(source, arguments) {
var isValidDate;
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "CustomValidate.asmx/AJAX_Test",
data: '{date1: "' + arguments.Value + '"}',
dataType: "json",
async: false,
success: function(result) {
isValidDate = result;
},
error: function(httpRequest, textStatus, errorThrown) {
alert("status=" + textStatus + ",error=" + errorThrown);
}
});
arguments.IsValid = isValidDate;
}

It always return javascript undefined error. But if I put the AJAX_Test webmethod in aspx page and replace the url: "CustomValidate.asmx/AJAX_Test" to "mypage.aspx/AJAX_Test". It works fine.

View 1 Replies

MVC :: Returning A Function In JSON?

May 26, 2010

I would like to return an function in some JSON. How can I stop my function being output as text (how can i stop it being wrapped in quotation marks?).

eg: [Code]....

In script the value of name is just a string. Is there some object I can set name to that will wrap my script and emit as script not a string?I want to do this to better control the "remote" rule of jQuery validate. I have my own dataannotationmodelvalidator for it and its doing this atm:

[Code]....

Which is working fine for the most part except I can't get the value of 'name' to be a function. It comes out as a string. Alternatively is there someway to control what JSON serializer this thing is using alternatively. We need a wrapper function so you can do something like:

name = Emit("function(){ return $(this).val(); }")

and have it come out as script not a string.

View 6 Replies

MVC :: Returning Pure Json From An App?

Aug 2, 2010

I want to return pure JSON from an MVC 2 Action. How can i do this?

View 4 Replies

MVC JSON Actions Returning Boolean?

Sep 20, 2010

I had my ASP.NET MVC actions written like this:

//
// GET: /TaxStatements/CalculateTax/{prettyId}
public ActionResult CalculateTax(int prettyId)
{
if (prettyId == 0)
return Json(true, JsonRequestBehavior.AllowGet);
TaxStatement selected = _repository.Load(prettyId);
return Json(selected.calculateTax, JsonRequestBehavior.AllowGet); // calculateTax is of type bool
}

I had problems with this because when using it in jquery functions I had all sorts of error, mostly toLowerCase() function failing.

So I had to change the actions in a way that they return bool as string (calling ToString() on bool values), so that thay return "true" or "false" (in the qoutes) but I kinda don't like.

How others handle such a case?

View 1 Replies

Returning A JSON View In Combination With A Boolean?

Apr 13, 2010

What i would like to accomplish is that a partiel view contains a form. This form is posted using JQuery $.post. After a successfull post javascript picks up the result and uses JQuery's html() method to fill a container with the result.

However now I don't want to return the Partial View, but a JSON object containing that partial view and some other object (Success -> bool in this case).

I tried it with the following code:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, Item item)
{
if (ModelState.IsValid)
{
try
{

[Code].....

However I don't get the HTML in this JSON object and can't use html() to show the result. I tried using this method to render the partial as Html and send that. However this fails on the RenderControl(tw) method with a: The method or operation is not implemented.

View 2 Replies

MVC :: Javascript Not Returning Value To Controller

Jul 26, 2010

My js code is not returning my groupId back to the controller. Her is my js function:

[Code]....

I have checked for that the groupid comes in.

View 1 Replies

Mvc 3 Json Values Not Receiving At Controller?

Mar 22, 2011

the problem is that i am not able to recieve any value in the controller . what could be wrong? the code is here.

[Code]....

View 2 Replies

How To Pass JSON To Controller Action

Mar 6, 2011

I have some textboxes and a table of data created client side that I want pass to a controller as JSON.

I want to use Jquery to enumerate the table.

Assume I have 2 textboxes called name and age. Assume a table with 2 columns. one column with class called phonetype and one column class called phonenumber.

So how do construct the JSON from this?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved