Passing JSON From JQuery To ASHX?

Jun 1, 2010

I'm trying to pass JSON from jQuery to a .ASHX file. Example of the jQuery below:

$.ajax({
type: "POST",
url: "/test.ashx",
data: "{'file':'dave', 'type':'ward'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
});

How do I retrieve the JSON data in my .ASHX file? I have the method:

public void ProcessRequest(HttpContext context)

but I can't find the JSON values in the request.

View 5 Replies


Similar Messages:

JQuery :: UI Autocomplete Not Passing Correct Querystring To Ashx Webservice?

Dec 29, 2010

Setup: I have a RadioButtonList with two listitems (One Street, the other Schools). These define what type of search I want. I textbox with associated autocomplete. First you select which search to complete, and then start typing and the autocomplete will make . Autocomplete goes out to ashx webservice which pulls a list from the database.

I have tested the webserver and it works properly, so I'm thinking the problem is with my jQuery UI autocomplete. <div id="divSelectOne" style="padding:8px 3px 8px 3px; border-bottom:1px dotted #cccccc; background:#f9f9f9;"> <span style="font-weight:bold; color:#369;">Select One:</span><br />
<asp:RadioButtonList ID="radSelect" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text=" Street, City, Zip or Subdivision" Value="Street" Selected="True"></asp:ListItem>
<asp:ListItem Text=" School" Value="Schools"></asp:ListItem>

[Code]....

View 2 Replies

Passing ID Of Element To A C# Web Service (using JSON) From JQuery?

Mar 9, 2010

I have an containing a list of divs that jQuery turns into progress bars. On .ready, I build a list of all of these progress bars and for each one, call a webservice that gets a value indicating how full the progress bar should be. In order to do this, I need to pass the ID of the div to the web service.

Because the divs are inside a ListView, I manually set the id to be id="completionbar_<%# Eval("MilestoneID") %>"

However, when I pass this id into my web service, it comes up as "undefined" every time. When I view the source, it looks like it's set correctly.

Here's the jQuery that calls my web service:

<script type="text/javascript" language="javascript">
$(document).ready(function() {
$(".MilestoneCompletion").progressbar({ value: 0 });
$.each($(".MilestoneCompletion"), function(index, barDiv) {

[Code].....

I'm thinking maybe the script is executing before the DIV id is set by the ListView databind?

View 2 Replies

Passing Complex JSON Data JQuery To Action?

Dec 1, 2010

I have 2 classes that are used to mirror the data from an ajax call. One (Customer) contains a property which is name, and the other is an array of Products.

Public Class Customer
Private _Name as String
Private _Products as Product()
Public Property Name() As String

[Code].....

View 1 Replies

Passing Form Hiiden Feild To Ashx?

May 7, 2010

i have a image upload using a .ashx handler, but i need to get one of the form values inside the handler, i have tried

int compId = int.Parse(context.Request.Form["hdCompId"].ToString());
and
int compId = int.Parse(context.Request.QueryString["hdCompId"].ToString());

but i get a null reference, any ideas how i can do this?

View 15 Replies

JQuery :: Ashx Handler Using Jquery Autocomplete - Show Different Search Record

Sep 7, 2010

i have using jquery for autocompelete option and iam using ashx file, i have 2textbox, i need to show diffrent search record in the text box, iam using 2 ashx file to show the value using jquery, i want to user single ashx file instead of iam using 2 ashx handle filer can use switch case to handle this , i want to use 7textbox all textbox i need to do autosearch, how to handle this senario using jquery and ashx handler file

clsquery.updatetablestring = "select top 2 Cont_number from ASPrearrival_list where Cont_number";
clsquery.updatetablestring = "select top 2 custid,custname from ASCustomer where custname";
// this is my auto search iam using 2 handler file , i wants only one handler instead of 2handler
<script type="text/javascript" src="jquery.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$("#<%=txtcontno.ClientID%>").autocomplete("Handler1.ashx");
$("#<%=txtcname.ClientID%>").autocomplete("Handler.ashx");
}
);
handler ashx file
<%@ WebHandler Language="C#" %>
using System;
using System.Web;
using System.Data.SqlClient;
using ASbusinesslogic;
public class Handler : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string firstname = context.Request.QueryString["q"];
string sql = clsquery.updatetablestring;
sql = clsquery.updatetablestring+" "+"Like"+" '"+ firstname +"%'";
//string sql = "select top 2 mlid,mloname from ASlinermaster where mloname like '" + firstname + "%'";
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString()))
using (SqlCommand command = new SqlCommand(sql, connection)) { connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
context.Response.Write(reader.GetString(1)+ "-"+ reader.GetValue(0) + Environment.NewLine);
}
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
handler1
<%@ WebHandler Language="C#" %>
using System;
using System.Web;
using System.Data.SqlClient;
using ASbusinesslogic;
public class Handler1 : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
string firstname = context.Request.QueryString["q"];
string sql = clsquery.updatetablestring + " " + "like '" + firstname + "%' ";
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString()))
using (SqlCommand command = new SqlCommand(sql, connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
context.Response.Write(reader.GetString(0) + Environment.NewLine);
}
}
}
}
public bool IsReusable {
get {
return false;
}
}
}

View 7 Replies

HttpHandlers / Modules :: Passing Session / Cookie Values To Ashx Handler?

May 30, 2010

i am trying to pass a value, from my .aspx form to a ashx request via a session or a cookie,

the cookie exists but in the ashx it returns a null, and same with the session value.

View 3 Replies

Passing JSON Data To A Webservice?

Jul 8, 2010

I have two parameters (categoryName and categoryDescription) that I need to pass to the web service using JSON. I found the syntax to pass categoryName but have not been able to get the correct syntax to pass both parameters. Here is the code.

<script src="js/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {

[code]...

View 4 Replies

Vb.net - Passing Data To Webservice Using JSON?

Jun 22, 2010

I have successfully returned data from a ASP.Net webservice in JSON format (using a service method that required no parameters) but have struggled with making a webservice call that requires a parameter.

Webservice:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function TestWebService(ByVal Description As String) As Stock
Dim res As New Stock(Guid.NewGuid, Description)
Return res

[Code]....

View 1 Replies

JQuery :: Display Pop Up In Ashx.cs?

Jun 23, 2010

I have created webpage and I am calling it from Jquery function. Technically I am {info} is image button and I am replacing with it with aspx

.replace("${info}","/_layouts/webpage.aspx");

The web page is opening in new browser window. Is there any way that I could make it as pop up whereever I can place in the page. That is get rid off the toolbar address bar. It should look like a pop up.

View 2 Replies

Javascript - Passing JSON To Controller Action

Mar 7, 2011

I have the following javascript. Problem is if I enter one row in the table "ingredients" but I am getting 2 rows in the resulting pass to controller action after seralising into my C# object. But the second object is null? I checked the javascript and the variable "cnt" is 1 not 2. Why would that be?

[code]

$("#Save").click(function () {
var title = $("#recipetitle").val();
var category = $("#category").val();
var preptime = $("#prepTime").val();
var preptimeperiod = $("#lstPrepTime").val();
var cooktime = $("#cookTime").val();
var cooktimeperiod = $("#lstCookTime").val();
var rating = $("#rating").val();
var method = $("#method").val();
var jsontext = '{ "RecipeTitle": "' + title + '",';
jsontext += '"CategoryID":' + category + ',';
jsontext += '"PrepTime":' + preptime + ',';
jsontext += '"PrepTimePeriod":"' + preptimeperiod + '",';
jsontext += '"CookTime":' + cooktime + ',';
jsontext += '"CookTimePeriod":"' + cooktimeperiod + '",';
jsontext += '"Rating":' + rating + ',';
jsontext += '"Method":"' + method + '",';....................

View 1 Replies

Display An Ashx Image Using JQuery?

Dec 30, 2010

I've been trying to use the jQuery plugin Colorbox to display images I have in my DB through an ashx file. Unfortunately it just spits a bunch of gibberish at the top of the page and no image. Can this be done? Here is what I have so far:

$(document).ready
(
function ()
{
$("a[rel='cbImg']").colorbox();
}
);
...
<a rel="cbImg" href="HuntImage.ashx?id=15">Click to see image</a>

UPDATE:

My ashx file is writing the binary out:

context.Response.ContentType = "image/bmp";
context.Response.BinaryWrite(ba);

View 4 Replies

JQuery :: How To Get Data From Ashx File

Oct 17, 2010

i have a ashx file

this file return string (plain/text)

i want ro read this from another page

Like:

http://www.domain.com/My-ashx.ashx?q=1 (This URL Return One Line Plain/Text)

i have another page: http://www.domain2.com/default.aspx ( I want write string(Return From ashx file))

View 4 Replies

Passing A JSON Object To A Function On Server Side?

Jun 4, 2010

I'm trying to create a JSON object on client-side and pass to a server-side function. Then instantiate it on server-side using JSON string representation.

So I create jSON object on client-side

var myJsonObject = {
"arg1": var1,
"arg2": var2
}

and pass it in to

WebForm_DoCallback(controlID, myJsonObject , null, null, null, true);

When I try to retrieve this JSON object on server-size I get as a string representation of JSON [object Object]

So in following server-side function, the argument value is [object Object]

public void RaiseCallbackEvent(string jsonObj)

I was expecting a string representation of JSON object. How do I pass in a string representation?

View 1 Replies

C# - Passing JSON Serialized Data Via Hidden Field?

Mar 2, 2011

In ASP.NET WebForms I want to pass arbitrary data from server to client and back again. I am serializing to JSON and have been simply producing JavaScript that creates the object on the client. I have no problem sending data to the server with ajax, but there are situations where I also want to send a Javascript object data back to the server on postbacks. So I guess it needs to be in a hidden field.

1) What is the best way to do this in terms of minimizing complexity and optimizing space and efficiency? In researching this I discovered Protocol Buffers but there does not seem to be a good C# implementation. I did find one, but it was a couple years old and self-described as buggy so that scared me.

2) If I just pass a JSON string, how can I be sure it will be safe to include as the value for a hidden field? Is there any reason I might not want to do this? I could Base64 encode, but it seems like this adds a lot of overhead. What is considered the best or preferred method?

View 1 Replies

Passing JSON To A PageMethod That Expects A List<T> Parameter?

Jan 13, 2010

I have an ASP.NET PageMethod with the following signature:

<WebMethod()> _ Public Shared Function SaveCodes(ByVal codes As List(Of Code)) As String

I am trying to pass a JSON object to the PageMethod from the client side, but I get an error that the type String cannot be converted to type of List<Code>.

Here is the json that I'm building on the client and sending to the method:

[code]....

I have been able to pass in simple data types and a single instance of the Code class, but I can't seem to find the magin to pass a List to the server method. Can anyone show me what I'm doing wrong?

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

MVC :: Passing Json Collection Object From View To Action

Nov 1, 2010

I am trying to send json data from view to controller action. But the issue is the data is not populating in the action parameter List<Score>.

View Model:
public class Score
{
public int QuestionId { get; set; }
public int PrevAnswerId { get; set; }
public int CurrAnswerId { get; set; }
public string CurrAnswerName { get; set; }
}

Json Data look like:
[
{QuestionId:1, PrevAnswerId:3, CurrAnswerId:3, CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7, CurrAnswerId:7, CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}
]

On window load, I will construct the Json object using "eval()" function and do some operation in the data before its save. On Save Click, I will call the action through the ajax call.

$.ajax({
url: url,
type: "GET",
dataType: 'json',
data: {score: ScoreJson},
contentType: "application/json; charset=utf-8",
success: function () {
alert("succes");
},
error: function () {
alert("error...");
} });

Action:
public ActionResult SaveScore(List<Score> score)
{
// do something...
}

But here score comming as collection of 3 elements with zero(for interger property)/null(for string property) values. When I checked in the request I found the data in "parama" property like.

"Score%5b0%5d%5bQuestionId%5d=1 &Score%5b0%5d%5bPrevAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerId%5d=3 &Score%5b0%5d%5bCurrAnswerName%5d=Known+to+broker&
Score%5b1%5d%5bQuestionId%5d=2 &Score%5b1%5d%5bPrevAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerId%5d=7 &Score%5b1%5d%5bCurrAnswerName%5d=Completed&
Score%5b2%5d%5bQuestionId%5d=3 &Score%5b2%5d%5bPrevAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerId%5d=10 &Score%5b2%5d%5bCurrAnswerName%5d=Travelers+Report&".

But I am not sure why it is not getting populated in the score list. One full day I spent for this issue but till now I didnt find the solution for this issue.

View 4 Replies

JQuery :: Validate Request And Web Handler(ashx)

Jun 24, 2010

I have a webpage where I am displaying some data.

On the top of that I have a button. On click of this button I am calling my webhandler using jquery/json, passing in some data to this handler. Now this data can containg html tags. So whenever I try to click that button it gives that Potential threat script

error. So I thought let me include ValidateRequest = false to my webpage.

Now when i do this it never hits my handler. I tried to debug also but my breakpoint is never hit in my handler. How to handle this.

This is how I call my handler:

[Code]....

where hidden value is the value which I want to pass to my handler and may contain html tags..

View 2 Replies

JQuery :: How To Save And Retrieve Date In Database Using Jquery Ajex .net ,JSOn,XML,HTML

Oct 13, 2010

how to save and retrive date in database using jquery ajex asp.net ,JSOn,XML

View 2 Replies

JQuery :: Gridview Textbox Template Save Using Jquery Json?

Mar 11, 2011

my requirement is i want grridview textbox template save using jquery json how to do it

View 2 Replies

C# - JQuery UI Re-populate Autocomplete Textbox With Ashx Handler?

Feb 3, 2011

Apologies for posting the ten billionth jQuery autocomplete question...I'm having trouble with a jQuery UI autocomplete textbox.I'm unsure if I'm doing the right thing client-side to re-populate the autocomplete data source following keystrokes.The javascript in my aspx page is as follows:

$(function() {
$("#<%=txtAuthorityName.ClientID%>").autocomplete({
minLength: 2,

[code]...

View 1 Replies

Javascript - How To Make Json Child Nodes (JSON Inside JSON)

Aug 11, 2010

I try to use the jquery + json to get all elements in form and build a JSON var to post in a ASP.NET MVC method.

[Code]....

It method get all fields in a form and build a JSON, but it dont put JSON inside JSON.

Example:

If i have the follow form:

<input name="person.name"><input name="person.age"><input name="person.address.street">

The serialized string build a JSON like this

{ "person.name": "??", "person.age": "??", "person.address.street": "??" }

I need a plugin or some function to generate like this:

{ "person": { "name" : "??", "age" : "??", "address":{ "street": "??" } } }

View 1 Replies

MVC :: Json And Jquery With Dropdownlist?

Sep 28, 2010

I want to do like below:I have three dropdownlist:

- test
- test1
- test2
and i have two textbox
- txtname
- txtsex

when i click on test dropdown list i want to diplay data in test1 dropdownlist and display in txtname and txtsex too, how can i do by using mvc json and jquery ?

View 2 Replies

JQuery :: JSON Not Working In IE?

Oct 8, 2010

I use a web method with JSON which controls the Username is available or disable. This code is working well with Mozilla. But it doesn't work with IE.

this is my JSON code:

<script src="../jquery-1.4.1.min.js" type="text/javascript"></script>
<script type = "text/javascript">
$(document).ready(function () {
$("#<%=txtUserName.UniqueID%>").change(function () {
var uname = $("#<%=txtUserName.UniqueID%>");

[code]....

View 8 Replies







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