JQuery :: Parse Or Use Returning A String Array From Websevice?
Dec 27, 2010i wrote a webservice method. i am using it with ajax jquery. method returns string[] array. ho can i read array's values using ajax jquery.
View 3 Repliesi wrote a webservice method. i am using it with ajax jquery. method returns string[] array. ho can i read array's values using ajax jquery.
View 3 RepliesIn my web form I have a search box. The user enters a string, and once the search button is clicked, I pass the value from my .js file to my .cs file and do some processing to get the results. Up to this point everything is fine, but now I dont know how to get my results back to my .js page. The serach results at this point are in a dataset, and also in an multidimensional array. I have a multi array because I need to pass back the code and description of the items found.
[Code]....
At this point I have used the passed string 'value' to get my required code/descriptions, but i'm not sure how/if I can get either the Dataset or multidimensional array back to my .js page
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 ?
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();
}................
I have a String that contains the following: ?workarea=London+&+Home+Counties+Ltd&sub=fs&&&FASh*5which resembles a URI query string. What is the best way to parse the elements of this string (workarea and sub) without messing about with string manipulation?If I use HttpUtility.ParseQueryString is gets stuck as both elements include &. However if I encode the whole thing first I lose the seperations of the elements. Ideally the output would be:workarea = London & Home Counties Ltdsub = fs&&&FASh*5
View 4 RepliesIs there a way to easily split a comma delimited string into variables (or table fields), example:
PHP Code:Feed.SmulocV2.Equipment,CAT,,DFT08783,2567,Hours,2010-02-07 06:37:41,Lat:38.025921,Lng:-88.776733
I have, somehow, this string available "20100205 162206". This is a date and time without any delimiter char. I need this back as a DateTime in C#. What is the best way?
View 1 RepliesGiven a string like:
Token A^*!%~Token B^*!%~Token C^*!%~Token D^*!%~Token E
Write a method that parses the string into a series of substrings where the delimiter between the substrings is ^*!%~ and then reassembles the strings and delimiters into a single new string where each of the substrings is in the reverse order from the original string. The method must return the final string. The expected output would be:
Token E^*!%~Token D^*!%~Token C^*!%~Token B^*!%~Token A
If I have a file in a path lke this:
C:demo estfile.txt
I can a split function and split on the backslash character to get the pieces. But if my directory could change this wouldn't work. So how would I instead parse out the last backslash and get the filename that way so that it wouldn't matter if the path changed?
How can i display the string variable data "234,345,567,678" into a listbox? i wish to parse the delimited string as seperate items.
View 4 RepliesI have a ListBox on my page. I'm making an AJAX call to a C# function, and I need to pass the values of the selected items. Here's what I have:
$('#btnSubmit').click(function() {
$.ajax({
type: "POST",
url: 'Default.aspx/GetSelectedValues',
data: '{selectedValues: ' + $('#lbItems').serialize() + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess
});
});
<select id="lbItems" multiple="multiple">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
[System.Web.Services.WebMethod]
public static string GetSelectedValues(string selectedValues)
{
//
}
The data being passed to the C# function looks like:
lbItems=1&lbItems=3&lbItems=5
Is there any built-in C# function that can deserialize that easily, to convert the values into an array of some sort? Or maybe there's a better way to pass the data from jQuery?
I have not been able to create a function to take a long nvarchar (8000) with a delimeter to return the results in a table . I have a script version that works as a query. I plan to use the Function in a Select * FROM table WHERE FirstName IN dbo.ListOfItem(@InputList) Is the following posible in SQL Server 2005?What is wrong with syntax? Is there a better solution?
[Code]....
After much head scratching as to why my returned Json string is breaking JSON.parse, I have realized that it is the returned dates that it doesn't like.
.net property:-
[code]....
I would like to split the string to the string array.
but when the string hasn't has the splite sperator, i can't put the string into string array directly.
how to do?
if (Str.Contains(','))
{
str_array=Str.Split(',');
}
else
{
str_array=Str; <-- error occurs at this line.
}
how to use a webmethod inside serverside file(.cs)which is present inside asmx file ??
View 1 RepliesI'm using the ajax auto complete extender and everything works fine. What I need now is a solution how to send additional information (variable) into the method of the autocomplete extender in the webservice. I need this variable to specify the WHERE-clause of my Access-String.
My Asp-Code:[Code]....
WebService- Code:
[Code]....
i have made a simple chat class but for displaying the msg i use a textbox but by ajax and page post back the scroll bar moves up and its very unprofessional so i need a way to set my returning function string to be displayed in div with scroll bar
View 3 RepliesI have a problem with getting jquery to retrieve results from a WCF service. I am hosting the WCF service within IIS and when I attach the debugger to this process I can see that the code is processed successfully. However, when it hits the callback within jquery there is no data??
I have set up a trace on the wcf service and there are no errors. It just seems as though the data is lost after the wcf service method completes.
Here is the jquery code which calls the service:
$.get("http://ecopssvc:6970/ecopsService.svc/Echo", {echoThis: "please work"}, function(data) {
alert("Data Loaded: " + data);
});
Here is the wcf config:
<system.serviceModel>
<services>
<service name="EcopsWebServices.EcopsService" behaviorConfiguration="EcopsServiceBehaviours">
<endpoint address="" behaviorConfiguration="WebBehaviour"
binding="webHttpBinding" bindingConfiguration="" contract="EcopsWebServices.IEcopsServiceContract" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehaviour">
<webHttp />
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="EcopsServiceBehaviours">
<serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Here is the service contract:
[ServiceContract]
public interface IEcopsServiceContract
{
[WebGet]
[OperationContract]
string Echo(string echoThis);
}
Here is the Service implementation:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class EcopsService : IEcopsServiceContract
{
#region IEcopsServiceContract Members
public string Echo(string echoThis)
{
return string.Format("You sent this '{0}'.", echoThis);
}
#endregion
}
I have integrated sandbox paypal into my application.After successful payment i am not getting success in the query string.Instead i get is return to merchant but if i do cancel i get the cancel in the query string
View 1 Repliesstrring[] arritem={"1"};
int i=convert.Toint32(arritem[0]);
now error will throwed.how to slove this problem?
I am having trouble with parsing a srtring, let me figure out :
This is my string (being gathered from DB) : students/notes/8293/location/michael.jpg
and i want to parse "michael.jpg" from this string to be able to process it.
I am using Entity Framework to contact my data base. as part of my web code I am using Linq to entities, and I want to determine the number of elements in an anonymous type list. I can't get it to work, I get the exception: "LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression."
var questItem = from chapters in context.TestChapter
from questions in context.Question
where chapters.ID == int.Parse(Request.QueryString["id"])
where questions.TestChapterID == chapters.ID
select questions.ID;
int numOfSteps = questItem.Count();
how can I get it to work?
obj.From = DateTime.Parse(txtFrom.Text, ci);
And it will give error String was not recognized as a valid DateTime. How it can be solved..
I am having problems returning a string value through a stored procedure/linq to a label. Everything works fine if I return an integer value but I cant get a string value to bind to a label. I get the error message
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value,
NumberFormatInfo NumberFormat) +201
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +66
[InvalidCastException: String "System.Data.Linq.SqlClient.SqlPr" to 'Integer' is invalid‚]
This is the stored procedure
ALTER PROCEDURE test
AS
Select ProductName
From Products
This is the vb page
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim db As New DataClassesDataContext
Dim product As Integer = db.test.ToString
Label1.Text = product
End Sub
This is the aspx page
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</form>
[URL] .....
I have an error with this tutorial.
Line 13:
Line 14: Private Sub BindGrid()
Line 15: Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Line 16: Using con As New SqlConnection(constr)
Line 17: Using cmd As New SqlCommand("Customers_CRUD")
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Public Class tessatusatu
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
[Code] ......