Using JQuery $.ajax To Pass String Value?

Mar 12, 2010

I'm using ASP.NET and attempting to call a method with a signature of

[WebMethod]
public static string GetInfo(string id){...}


using the following javascript:

var elementValue = $("#element").attr('id');

[code]...

And this is not working.If instead I set elementValue = 2; it works fine. If I try to hardcode in a string value for testing purposes e.g. elementValue = "nameToLookUp"; It fails.Why is this happening, and how do I resolve it?On a side not, why is type: required to be POST instead of a GET? In the end I just want to pass a string value I want to look up in a DB and retrieving some json data.

View 2 Replies


Similar Messages:

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

AJAX :: Pass Query String To Modal Pop Up?

Mar 23, 2011

This is how my modal popup looks like

[Code]....

The link AddPayment.aspx i need to change it to AddPayment.aspx?ID=something from code behind, how do i do that?

View 1 Replies

Pass Control To A JQuery Ajax Call?

May 5, 2010

I have the following jQuery event that gets fired every time an anchor is clicked. How can I pass a asp.net control (lets say a panel called "pnl_info") as one of the parameters, in addition to the "target" parameter i'm already passing?

<script type="text/javascript">
$(document).ready(function() {
$("a").click(function(event) {
$.ajax({
type: "POST",
url: "Default.aspx/Click",
data: "{target:'" + event.target + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.responseText);
$("#myContent").html(xhr.statusText);
//alert(xhr.responseText);
},
success: function(msg) {
alert(msg.d);
}
});
return false;
})
})
</script>

View 1 Replies

AJAX :: Jquery Dialog Box + MVC / How To Pass Some Elemet [id].val Into ModelState

Feb 23, 2011

I send to my view via a ViewModel few List of entities

[Code]....

My view contain a form to create a futur object "Skill"Inside of it you will have a dropdownlist of "Categories" My dialogBox is used to Add or Edit these Categories.I use Ajax to submit the CategoryEdit form to the corresponding Controller.

[Code]....

[Code]....

Unfortunatly My controller lost all of my ViewModelState and can't find any argument.

My controller:[Code]....

I really want to use the dialog box offer by jquery. I just need to know haw to pass some elemet[id].val into my ModelState.The thing is when I open this dialog box and check with firebug "View form Information" It finds only the element from the previous page (I mean the Skill Form).

View 2 Replies

JQuery :: Ajax Security To Pass Information To The Second Page?

Jun 22, 2010

I was looking at using the Jquery request to call a second aspx page which either inserts or selects records from the database. My concern is the security of using Ajax. To pass information to the second page the Ajax request constructs a query string which is read from the second page. However, I don't know if I feel comfortable having the query string parameters so easily accessible. Especially if inserting records using Ajax anyone could follow the page being pointed to and then just load that into a new window with the query strings filled in.This would result in potentially a database attack adding many fake rows.Are there any security measures I can put in place to keep my Ajax secure or preferably hidden?

View 2 Replies

Jquery Ajax Call To Web Service - Can´t Pass Parameters?

Nov 6, 2010

I´m using jQuery to make the ajax calls to web services. I´m not using json, I want the information in XML. If I don´t pass parameters and I make the WS parameter less it works but if I want to pass a value as parameter (I tried int and string) it doesn´t work. Here is my code:

jQuery: [Code]....

The web service

[Code]....

The error that I get from firebug is an exception System.InvalidOperationException and it says that the parameter region_id is missing.It can´t be very difficult because it works without parameters but all the information I find in internet

View 5 Replies

AJAX :: Pass And Save JavaScript Array Values To Database Using JQuery?

May 7, 2015

I have create a web page having dynamically created text boxes if  i select value in dropdown list,text boxes auto generates .but i want to save all text box values in SQL server database after clicking on submit button using ajax/JSON request

View 1 Replies

State Management :: How To Pass Dynamic String Through Query String With Java Script

Dec 24, 2010

I m facing some problem. i m not passing Dynamic string through query string..

I m using this code

string abc = "CPCB_" + TextBox1.Text + "_" + TextBox2.Text;

Response.Write("<script>window.open('xml.aspx?Flag=3&date='+abc,target='new');</script>");

View 2 Replies

JQuery :: Passing A Long String (longer Than 2048) With $.ajax?

Jul 18, 2010

I have a htmlarea (Jquery plugin) where I need to accept longer strings than 2048 which seams to be the limit. I don't have a clue where to look. It's an MVC app and here are the relevant code:

HTML:

<div id="PageTextDialog" title="Ă„ndra texten pĂĄ sidan" style="display: none">
<% Using Html.BeginForm %>
<%: Html.TextAreaFor(Function(model) model.PageText, 30, 30, New With {.style = "width:800px;"})%>
<% End Using%>
<button id="SavePageText">Spara</button>
</div>

JScript:

$(function () {
function SaveText(pageID, htmlText) {
var retvalue = false;
$.ajax({
async: false,

[code]...

View 2 Replies

C# - Cannot Pass A Input From Text Box To A Query String And Then Keep The String In This Box?

May 28, 2010

I have a simple ASP.net page:

<form id="form1" runat="server">
<p><asp:TextBox id="input_box" runat="server"></asp:TextBox>
<asp:Button Text="OK" runat="server" OnClick="run" /></p>
</form>

I want to send input from input_box to a query string, and then keep this input in the input_box when the page reloads.

That's the code behind page:

protected void Page_Load(object sender, EventArgs e)
{
input_box.Text = Request.QueryString["input"];
}
protected void run(object sender, EventArgs e)
{
string url = string.Format("?input={0}", input_box.Text);
Response.Redirect(Request.Url.AbsolutePath + url);
}

Problem is that when query string is not empty, string from input_box cannot be passed to query string. How to correct it?

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

Passing Folder Path String To Web Service Function Via JQuery.ajax?

Apr 24, 2010

I need to perform asp.net web-service function call via jQuery and pass asp.net application path to it. That's the way I'm trying to do it (code is located within asp.net page, e.g. aspx file):

[code]...

Function call works well, but applicationPath parameter doesn't passed correctly. When I debug it I see that backslashes are removed, function gets "C:ProjectsSamplesmytestwebsite" instead of "'C:ProjectsSamplesmytestwebsite'".

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

Data Controls :: Pass Multiple GridView Row Data To Web Method / Save To Database Using JQuery AJAX

May 7, 2015

I want to add  gridview row data into to data base I am doing it perfectly.My problem is that want all gridview row data save and then web method should be called but in my cause one  gridview  data save in array then call webmethod,then other row data save in array then call webmethod called this process should be so on.But I want it webmethod should be called when all gridview row save in array.

Follwing code

Jquery
<script type="text/javascript">
$(function () {
$("[id*=btnSubmit]").bind("click", function () {
var Customer = {};

[code]....

View 1 Replies

JQuery :: Pass Control's Value To JQuery Autocomplete?

Dec 31, 2010

On my page I have four controls:

How to pass control's value to jQuery autocomplete

View 1 Replies

(C#) Jquery "make Return String" Ajax With WebMethod Call

Mar 25, 2010

[WebMethod]
public static string emp()
{
return "BlaBla";
}
Aspx Page:
$(document).ready(function() {
$.get("TestPage.aspx/emp", null, function(data) {
alert(data);
})
})
Message Box Output: TestPage.aspx on the page codes
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title>
<style>
tr
{
background-color: red;
color: White;
}
</style>

How to make return string?

View 1 Replies

Pass String Contains '+' Via The Querystring?

Apr 22, 2010

I need to pass '+' via the QueryString.

some special character can be passed by using 'Encode' .. but '+'

I know the one solution, If I replace '+' with other character.

But it's not the perfect solution.

[edited]

well I used escape() javascript function to encode.

escape function can't encode + . is the another function to encode on javascript?

View 4 Replies

Pass Value In String S Onto A New Webpage In C#

Nov 8, 2010

i want to pass a string value from one page to another.Also i have some text boxes and the values entered in it needs to be passed to a new page.How do i do it?

I have a string S

String S = Editor1.Content.ToString();

i want to pass value in string S onto a new page i.e Default2.aspx how can i do this in ASP.net C#

View 3 Replies

MVC :: Pass A String Value To A Controller Action?

Feb 16, 2011

I am trying to get this functionality on my jokes website:

www.mysite.com/category/bar

To get all the bar jokes ..etc

The way I have my route right now is:

{controller}/{action}/{id}

which means I have to type:

www.mysite.com/category/index/bar

the problem is that even with that, the string parameter "bar" isn't being acknowledged ! ( I know from debugging). Here is my Index action in the Category controller:

[Code]....

View 8 Replies

How To Pass Date In Query String

Mar 4, 2010

I have a textbox with a date field in dd/MM/yyyy format.

I am passing it to popup page via query string. Problem being is that it is translated there as MM/dd/yyyy

How do I fetch the date correctly guys ? My code on parent page gridview

[Code]....

View 8 Replies

C# - Pass String Parameter To SqlDataSource?

Sep 16, 2010

i have placed a SqlDataSource component on my aspx page but while configuring the SqlDataSource in the "Test Query" Step I am passing the following parameters :But when i click ok it returns following error:This error occurs when i pass the string :

INFO, WARN, ERROR,

I have tried a lot of combinations but nothing works. It works only if i pass one of the three words in single quotes like this :'ERROR'Infact the INFO WARN and ERROR are the various levels available in the table. Each record can have only one level and in the sql query i am using IN("-----") to match the criteria, hope you understand.

View 2 Replies

Web Forms :: Can't Pass String From Database

Apr 23, 2010

I'm creating a dynamic menu, from the reading of a table in a database, everything is going well so far I need to read the url field that has the address of the pages, to appear in the masterpage, the problem can not I pass the string from the database for the navigateUrl.

<DataBindings>
<asp:MenuItemBinding DataMember="MenuItem"
TextField="Text" ToolTipField="ToolTip" NavigateUrl="pathurl"/>
</DataBindings>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>
<!-- Find the root node called Menus
and call MenuListing for its children -->
<xsl:template match="/Menus">
<MenuItems>
<xsl:call-template name="MenuListing" />
</MenuItems>
</xsl:template>
<!-- Allow for recusive child node processing -->
<xsl:template name="MenuListing">
<xsl:apply-templates select="Menu" />
</xsl:template>
<xsl:template match="Menu">
<MenuItem>
<!-- Convert Menu child elements to MenuItem attributes -->
<xsl:attribute name="Text">
<xsl:value-of select="Description"/>
</xsl:attribute>
<xsl:attribute name="ToolTip">
<xsl:value-of select="Text"/>
</xsl:attribute>
<xsl:attribute name="pathurl">
<xsl:value-of select="url"/>
</xsl:attribute>
<!-- Call MenuListing if there are child Menu nodes -->
<xsl:if test="count(Menu) > 0">
<xsl:call-template name="MenuListing" />
</xsl:if>
</MenuItem>
</xsl:template>
</xsl:stylesheet>

View 2 Replies

How To Pass A String From .aspx To A Class

Feb 24, 2010

I need to pass a string from my .aspx page to my .VB class.

i need to capture (device_category; accept_headers : user_agent) and pass the values to my class, i tryed to captur the values on the clas itself but i got an error(valuse are not member of this class..)

How can i have a string accessable to my class?

View 10 Replies

How To Pass A Value To A String From A Local Resource

Feb 11, 2010

I have created a webpage called server.aspx and the related local resource file called server.aspx.resx. In the resourcefile I defined the message "{0} is required." with the key Error.

In my .aspx page I access the string:

<asp:RequiredFieldValidator ControlToValidate="textboxName" runat="server" ErrorMessage="<%$ Resources:Error %> ID="validatorName">

Now I want to pass a value, for example the name of the textbox 'Name' to the resource string, so that the errormessage is "Name is required."

Is there any possibility to pass a value to the string?

View 2 Replies







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