Web Forms :: Pass Multiple Name Value Pair JSON To WebMethod?

Sep 10, 2012

This is regarding your article on 

[URL]

I have a json object with multiple Name & Value pairs,  I am using example on above given link but it is not calling the Web Method.

var jd = [];
jd.push({ ID: HArr[j], Val: Str });
var jd = [];

[Code].....

In my class I have a Web Method defined as :

[System.Web.Services.WebMethod]
public static jsonData PassJsonData(jsonData jd)
{
return jd;
}

View 1 Replies


Similar Messages:

Pass Optional Parameters Into A WebMethod Via JSON?

Feb 15, 2010

I have the following JSON class I am intending to use to perform management calls on my database asynchronously:

<script type="text/javascript">
var CalendarManager = {
defaultOptions: {
staffcode: 0, // required
date: 0, // required

[Code]....

Basically, my question is: how do I specify optional parameters to a WebMethod when providing JSON data?

I know I can reduce the parameters down to just the required values, and then use HttpContext.Request.Params to read the values of optional paramaters, but I would have thought the way I have tried here should have worked.

EDIT

The XMLHttpRequest.responseText value for the error is:

Invalid JSON primitive: staffcode.

This is throwing me even more off the scent of the problem :(

View 2 Replies

Data Controls :: Pass JSON Data Object From JQuery AJAX To WebMethod

May 7, 2015

I want to send single json object with nested arrays through jquery ajax method.

In Code

In jquery ajax i am passing LeaveRuleMaster a single json object which holds some properties (Leavetypeid, Leavename, Leavestatus and nested array LeaveRulespecific.

In vb.net code i can receive the value of properties(Leavetypeid,Leavename,Leavestatus)

but i am receiving the LeaveRuleSpecific as nothing.

Based on the following link i tried this [URL] .....

View 1 Replies

C# - Serialize .NET Dictionary<string, String> Into JSON Key Value Pair Object

Feb 26, 2011

public class Package
{
public Package()
{
name = "";
type = new List<Dictionary<string, string>>();
}
public string name { get; set; }
public List<Dictionary<string, string>> type { get; set; }
}
[code]...

View 2 Replies

WebMethod Return Values In JSON Format?

Jan 24, 2010

How to return values from Webmethod to the client in JSON format? There are two static int values that i want to return.Do I need to create new object with those 2 properties and return it?The GetStatus() method is called frequently and i don't like the idea of creating a special object each time just for json formatting...

[WebMethod]
public static int GetStatus()
{
int statusProcess,statusProcessTotal;
Status.Lock.EnterReadLock();
statusProcess=Status.Process; //Static field
statusProcessTotal=Status.ProcessTotal; //Static field
Status.Lock.ExitReadLock();
return ...
}
On client side I catch the return value in :
function OnSucceeded(result, userContext, methodName)
(PageMethods.GetStatus(OnSucceeded, OnFailed);)

View 1 Replies

ASP WebMethod Returns JSON Wrapped In Quotes

Jun 8, 2010

I have an asp.net page with a WebMethod on it to pass JSON back to my javascript. Bellow is the web method:

[WebMethod]
public static string getData(Dictionary<string, string> d) {
string response = "{ "firstname": "John", "lastname": "Smith" }";
return response;
}

When this is returned to the client it is formatted as follows:

{ "d": "{ "firstname": "John", "lastname": "Smith" }" }

The problem is the double quotes wrapping everything under 'd'. Is there something I've missed in the web method or some other means of returning the data without the quotes? I don't really want to be stripping it out on the client everytime. Also I've seen other articles where this doesn't happen.

View 2 Replies

Getting JSON As Parameters In Webmethod From JQuery AJAX

Mar 13, 2012

I'm doing an jQuery AJAX POST call to a webmethod, which is working fine. If I'm passing data from the AJAX call, I normally get the data in the webmethod via webmethod parameters.

JavaScript Code:
$.ajax({"dataType": "json","contentType": "application/json","type": "POST","url": "Default.aspx/GetStuff","data": JSON.stringify({"a":"data1","b":2}),"success": function (msg) {    console.log(msg.d);}});
C# Code:
[WebMethod]public static object GetStuff(string a, int b){ }

Is there any way I can get the data as a Dictionary or some other object, instead of having to put in individual parameters to the GetStuff() web method for each data param? It's a POST request so nothing is in Request.QueryString, and Request.Params/Request.Form doesn't contain it either.

View 2 Replies

How To Send A Collection And A Few Other Values In Json Form To A Webmethod?

Sep 28, 2010

Upon clicking a button I need to send a collection and a few other variables to server in Json form.For each value in the collection the server code (C# ) wil update those other variables in the DB.

For example there is a ‘classnumber’ collection with values (First, Second, Third, ….),other variables (‘teacher_name’ and ‘subjectname’).For each value in the ‘classnumber’ collection I need to update the ‘teacher_name’ by searching for the ‘subject_name’ in the DB.So I need to pass the ‘classnumber’ collection,’teacher_name’,’subject_name’ values to server in json form. At the moment instead of sending the ‘classnumber’ collection I am sending ‘teacher_name’,’subject_name’,’classnumber’ as variables for each value in the collection ,which requires multiple requests made to the server.

Instead of these individual requests I am wondering if there is a way to send all the data at once to server in json form?

View 1 Replies

AJAX :: Return Json Format From Page's Webmethod?

Jun 7, 2010

I have the following web method , no success on return a correct Json format.

[Code]....

GetAll() return list of type "Company" POCO classes.

The web method complaint type "Company" could not cast to object. However I could not just return the Company type because client side Json only accept its 2 properties -"CompanyName", "ID" and I want to keep it that way.

Of cause, I had tried create a CompanyDTO which only have those two properties, but same error - "Unable to cast object of type..."

How should I modify in my web method to make it able to return a list of partial "Company" type in Json format?

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

Data Controls :: Return XML As JSON List From WebMethod Using JQuery

May 7, 2015

I am trying to retrieve asp.net C# List method in JavaScript by referring Send-and-receive-JavaScript-Array-to-Web-Service-Web-Method-using-ASP.Net-AJAX ..My Code as below

Javascript

<script type = "text/javascript">
function GetAllSVGData() {
PageMethods.GetSvgElements(OnSuccessSVGElements);
}
function OnSuccessSVGElements(response) {

[code]....

My problem is JavaScript function OnSuccessSVGElements is not firing. When I put breakpoints in it is working fine in C#.  C# Method Working But Alerts in javascript not working.

View 1 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

How To Pass A DateTime Value To A WebMethod (ASMX)

Jan 7, 2011

I have a WebMethod with a parameter defined as DateTime. When I call that webservice, I get this error:

[Code]....

Where 'start' and 'end' time are two javascript 'Date' objects.

View 1 Replies

AJAX :: How To Pass More Than One Control Values To Webmethod For AutoCompleteExtender

Apr 5, 2010

I am developing a user control. This user control is having 2 Dropdown controls and one textbox('txtCustomer'). I am using autocompleteextender for the text box. This 'txtCustomer' control populates the data based on the value selected in 2 dropdowns.

I need to pass the selected value of this 2 dropdown to my meb method. I am not using web service(.asmx page) for this application instead i am using page level web method. I tried to access the controls from the web method inside the Page. but all the identifiers and controls of the page returning null in the web mothod. I have analysed it is because the events "page_Load and page_Init" are not getting fired.

View 6 Replies

AJAX :: Pass Some More Parameters In WebMethod While Using Cascading DropDown Extender?

Jul 28, 2010

I am using AJAX Cascading dropdown extender,and i have made a running dummy example.Using web service second dropdown is filled based on the selection of first drop down. But actual query that should fill second drop down have some more constraints in 'where' clause of the sql query, and that's value is too dynamic that (i cannot assume its value to be static). So i need that that variable's value in my web method too.

View 2 Replies

Data Controls :: Pass DataTable Or Dataset As Parameter To WebMethod Of WebService

Mar 16, 2014

can datatable pass to web service as input parameter? i have a scenario to pass values as datatable to web service. eg as follows

when Invoice or Bill is entered, I want to send the entered data as datatable to web service to insert into another application.

View 1 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

MVC :: Pass JSON Result To JQuery?

Feb 8, 2011

I have the following actionresult in my controller;

[Code]....

and this jquery script to print values pass from controller in textboxes.

[Code]....

View 8 Replies

C# - Returning Multiple Values To Be Used In JQuery From A WebMethod

Mar 3, 2011

I have jquery using ajax/json to grab an elements ID and then hits:

[System.Web.Services.WebMethod]
public static string EditPage(string nodeID)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(Global.conString))
using (SqlCommand cmd = new SqlCommand("contentPageGetDetail", con))
{
cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier).Value = Global.SafeSqlLiteral(nodeID, 1);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
if (dt.Count > 0)
{
string pageTitle = dt.Rows[0]["Title"].toString();
string contentID = dt.Rows[0]["ContentID"].toString();
return pageTitle, contentID, nodeID;
}
else
{
return "Failed";
}
}

When it's time to return I want to grab all content returned from the stored procedure back to the jquery method in the success section and set a hiddenfield, dropdown value, and a title in a textfield. In the jQuery I tried using "pageTitle" but it came up undefined. What do I need to do jQuery side to grab whats being returned and populate fields in my Web Form before showing the form?

View 3 Replies

Javascript - Tuple<string, Int> JSON To Pass To Wcf?

Mar 29, 2011

how to pass this via Json.Tried doing something like

var data = { Item1: "test", Item2: 5 };
var JSONdata = $.toJSON(data);

However that did not work. Although simply changing wcf to expect an object with two properties such as Item1 and Item2 will work. Here is example I'm using... I'll trim it a bit to make it easier to read:

function Post(data, url)
{
$.ajax({
type: 'POST',[code].....

View 1 Replies

Pass JSON To Webpage On Load Of Page?

Sep 6, 2010

I have a ASP.NET MVC 1.0 app.I have a listbox on the page and I want to pass an array to the webpage so that
javascript can use the array to do some processing depending on the item picked in the listbox.So I thought the best way is to pass JSON data to the webpage on load.So what is the best practice on how to do this?Can you please give me a brief step by step process.How do pass the array as JSON and how do I access it by index?

View 1 Replies

AJAX :: How To Return Multiple Values From WebMethod To JQuery

May 7, 2015

i want to return multiple(name and statusid) parameter from web method and want to retrive in javascript function how to use it. 

I have attached my code. 

[System.Web.Services.WebMethod]
public static string CheckPromotionCode(Int32 id)
{
string name="kausha";
string statusId = "6";

[CODE]...

View 1 Replies

Pass A String To A Web Service Using JQuery / JSON / AJAX?

Oct 29, 2010

As it is now I create a JavaScript object and then stringify it, put it in a hidden textbox and my code behind can read this string. I then use JSON.NET to parse the string which works fine. I now try to use ajax to post it to my web service but have some issues with how to send the string. I have tried many ways but gets the common errors like

Invalid JSON primitive: myString.

So I checked this out [URL] and it works with hard coded values but I want to use a variable.

JavaScsript to create the object:

for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(i);
var customer = new Object();
customer.id = row['id']
customer.name = row['name']
var customerString = JSON.stringify(customer);
$.ajax({
type: "POST",
url: "synchronise.asmx/synchroniseCustomers",
data: "synchroniseCustomers: " + customerString,
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (xhr, status) {
alert("An error occurred: " + status);
},
success: function (msg) {
alert("success");
}
});
}

WebMethod:

public void synchroniseCustomers(string customerString)
{
JObject o = JObject.Parse(customerString);
string id = (string)o["id"];
string name = (string)o["name"];

If I use data: '{ FirstName: "Dave", LastName: "Ward" }'

in the example above it works but I wish to pass on a string instead.

View 2 Replies

VS 2008 - Pass JSON String To Download Page

Dec 21, 2012

I've got code like this in a download page

Code:
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Download
Inherits System.Web.UI.Page

[Code] .....

That is called like this:

Code:
function excelGrid(strId, blnDoReader) {
var wesPC = $("#" + strId);
var objWebParam = {};
var arrGrid = [];

[Code] ....

I am modifying this now - passing in the variable strWebParam which is the "stringified" version of a JSON array. And then in the function below I am trying to get the JSON-string into the POST. I tried the INPUT/TYPE=HIDDEN method you see below - but that did not work (cut off the string - it's got quotes in it)

Code:
$.downloadExcel = function(url, data, source, method, callback) {
var inputs = '';
var iframeX;
var downloadInterval;
if (url && data) {

[Code] ....

When I do a regular AJAX post for something I use the "data" element of the $.ajax method like this

Code:
var strWebParam = $.toJSON(objWebParam);
$.ajax({
type: "POST",
url: "WebService.asmx/BootPage",
dataType: "json",

[Code] .....

How is that DATA: STRWEBPARAM getting passed back to IIS??

View 2 Replies

MVC :: Using Jsonresult Actions To Pass Json Data To Third Party Apps?

Oct 9, 2010

i want to use MVC 2 actions to pass JSON data to a 3rd party application via a URL.The URL will be in the form of http://www.abc.com/controller/action..I am using JSonResultHow can i test the output of this URL to ensure the JSON is properly formed..

View 2 Replies







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