AJAX :: Consume .asmx With JQuery (POST Method, Not JSON)?
Feb 4, 2010The ideal goal is to consume .asmx web service using jQuery like this
[Code]....
The ideal goal is to consume .asmx web service using jQuery like this
[Code]....
I have created a asmx web service.The service will interact with SQL Server database to Get, Insert and Update of some tables in my db.I have one Service method called AddItem which takes a class object as parameter. with that parameter I am inserting the values into the database. In the same way I have another service method that Gets all the Items from db using the same class and returns the class object as the return type for my service.
Here is my sample AddItem() and GetAllItems() prototype
Collapse | Copy Code
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.
I added a Web Method to the existing web service. I don't see this method in my web project. I can see all the old methods but I couldn't access this method. Do I have to create proxy for this method?
View 2 RepliesI defined two webservices calls in ASP.NET:
1.BeginLengthyProcedure and EndLengthyProcedure (Asynchronous web method)
2.LengthProcedureSync
namespace ServiceDemo
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class AsyncWebService : System.Web.Services.WebService
{
public delegate string LengthyProcedureAsyncStub(int milliseconds);......
What is the best way to create a Contract that will consume multiple database records? The database records will have 20 fields and maximun of 1000 rows.
View 1 RepliesHow can I upload files asynchronously with JQuery?
I have a file upload field, after the image was selected, i make a jquery ajax post to an aspx page's page method. My question is, how can I pass that image via jquery? When I do $(this).val() it only gets the file name. I want to pass the image object itself.
have this site that has an api that can provide city name if I send my zip code as a parameter. http://www.postnummersok.se/api?q=16447the result is returned as a json object. Now i just want to read the result in my js function.I have tried the following but it always returns null:
function postnr() {
we need to expose a web service to the 3rd party vendor which can only call using POST protocol, NOT SOAP.So my question, is it better to build a web service or just simply .aspx page?Also is there any best practice documentation on this.
View 4 Repliesi built contact form in aspx 3.5 and i'm using jquery to send it to web service (asmx).the web service need to return success or error code. the problem is that at the web method i get only single value and not array. I'm kind of new in ajax and i tried a lot of solutions but without any results.. please if you can only explain me the principle of what to do it also be good..this is the client side:
$(document).ready(function()
{
$("#submit").click(function(event)
{
[code].....
when i debug i see that the input parameter "name" contains only one string - i dont know how to get the full json string that i send to the service and contains all the form data - i want to desirialize it to string array or something like, and process it.
i need to be able to expose information to a page, and I need to write the information in xml on my webserver which will be dynamically created from the database.
I need to use json to pass the data from the screen back to the server two way communication xms back and forth. Is it actually any good using a wcf endpoint to serve the json back to the page and use query with wcf? Is this possible?
Or is it easier to use standard pages .aspx and just do a call to a url and get the json with jquery....
We will probably want to send this information to other locations at some point in the future too....
When this function is hit , it does not call my function in code behind? Why could it be doing this? How can I fix this error.
$(document).ready(function() {
$('[id$=btn_Update]').click(function() {
var reten = $('[id$=txt_Reten]').val();
var i=0;
var selectValues = "";
var ProdID = new Array();
$("#lst_ProdId option").each(function() {
selectValues = selectValues + $(this).text() + ",";
ProdID[i] = $(this).text();
i++;
});
for(var j=0; j < ProdID.length;j++)
{
// alert(ProdID[j]);
}
var params = "{'ProdID':'" + ProdID + "','RetenP':'" + reten + "'}";
$.ajax({
type: "POST",
url: "/ProductPricing/Products/RetenPeriod.aspx/UpdateRetenPeriod",
data: params,
contentType: "application/json; charset=utf-8",
datatype: "json",
success: function(result) {
alert("sucess");
},
error:function(e) {
alert(e.statusText);
// if(errorThrown != null)
// alert(textStatus+ ":"+errorThrown);
// else
// alert("fail");
}
});
return false;
});
return false;
});
This is my webmethod in code behind:
[WebMethod]
public static bool UpdateRetenPeriod(string[] ProdID,string RetenP)
{
for (int i = 0; i < ProdID.Length; i++)
{
update(ProdID[i],RetenP);
}
return true;
}
how to create a Web service that returns a JSON(or JSONP). That also should be able to work for cross-domain access aswell as for a local call.. help to get this working or for a few links for further reading about this
View 2 RepliesFor now, I just want to use HTTP POST to send json to asp.net mvc2 controller.Since the JSON is actually a list of JSON objects, and each of them has different fields & length, so it hard for me to make up a input model.So I want to know is there a way for me to post JSON without model/ajax to a controller in ASP.NET MVC2?
View 2 RepliesI'm trying to use the jQuery.post() function to post an object to an action method, but for some reason the nested objects aren't initialised properly when they're received by the action method.
Here's my javascript code:
[Code]....
And my action method:
[Code]....
company.Id has a value of 10, but company.User.Id is 0. what I'm doing wrong? I've not named any properties incorrectly, by the way.
We have a web application providing a service using a simple REST interface (GET/POST methods) and returning results in JSON format.
A client wants to use the service from an ASP application (I assume ASP.NET) and asks for example code.
Is there any standard/widely-acceptable procedure for consuming JSON based web services from an ASP.NET application? I'm not familiar with the .NET framework, but can work my way through C#.
$.ajax(
{
type: "POST",
url: "Default.aspx/GetAge",
data: "{}",[code]...
Right now it reports the following error: "Cannot locate the resource". I figure that I am specifying the url incorrectly. This javascript is in an external file located in the same directory as Default.aspx .
I am new to WCF, I was using web service asmx before. I have trouble on making my wcf JSON ajax service work through http like asmx.Could you help me see what wrong in my code?My WCF services are defined in my website application folder. My aim is to call this service in my aspx page java-script code and return complex object back as JSON to my javascript. I have no problem on doing this through classic asmx web service.
When I try to test it through my browser by type this in the URL , URL-http://localhost:3849/WebServices/Account/WCFCompanyService.svc/GetAll. it return "Method not allowed."
But if I type just this URL-http://localhost:3849/WebServices/Account/WCFCompanyService.svc, it return this:
WCFCompanyService Service
You have created a service.To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
svcutil.exe URL-http://localhost:3849/WebServices/Account/WCFCompanyService.svc?wsdl
This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service. For example:
C#
class Test { static void Main() { HelloClient client = new HelloClient();
[Code]....
This is my Ajax-enabled WCF service code:
[Code]....
This is the web.config service model setting
[Code]....
i working in asp.net mvc project and deployed in the windows 2003 with iis 6.server.But it post method in jquery is not working after hosting. it given all path of the script is correct with Url.Content. The same Project hosted working in xp with iis5.1 it working fine.Give me any solution to run post of the jquery in the hosting server windows 2003.
View 2 Repliesfunction createSuccess(context) {
$get("result").innerHTML = context.get_data();
}
<% using (Ajax.BeginForm(new AjaxOptions {OnSuccess="createSuccess"}))
{%>
What does context holds in the createsuccess method? data return by controller? How do we return json data in the createsucess if so
I am writing a sample jQuery/WCF Data Service app to utilize OData, however I am getting a status code 405 - Method not allowed when I attempt to update an entity with a PUT Http method. I have configured my WCF Data Service as follows:
[Code]....
I am attempting to update the jCredentials_PINs table. My jQuery call to update the WCF Data Service is as follows:
[Code]....
I am using Windows 7 / IIS 7.5. GETs against the jCredentials_PINs table work fine. The only web.config configuration information is as follows:
[Code]....
I have the following code where the function codeaddress geocodes the text feild value and returns geocoded value , geocoded value is stored in variable example ,how will i return the variable v2 to the function call and post to asmx webservice.
[code]....
i am new in json script.am trying to convert the database table value into json using asp.net with c#.here, am also send the response to asp.net client side.but am not receiving any response from server side.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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 runat="server">
<title>Untitled Page</title>
[code]...
I am reciving an XML file(probabbly genrated by webservice), when i request a web url. EVery desried information is in this xml file. Now my problem is to access this file in XML control. I have genrated xsl file for the same xml file.Assume below mentioned url giving me xml file.
strign url=http://remoteurl.com/abc?myvariable="myvalue"
I tried this code.
Xml1.Datasource=url;
Xml1.TransformSource=abc.xsl;
It is not working. However if i copy the content of xml file and save it inside website and name it abc.xml and type this line it is working fine..
Xml1.Datasource=abc.xml;
Xml1.TransformSource=abc.xsl;
i want to do it automatically.
client code:
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$("#send").click(function () {
$.ajax({
url: "../JqueryAjax/JqueryAjaxServer.aspx",
type: 'get',
contentType: "application/json; charset=utf-8",
dataType: "json",
timeout: 30000,
data: "{}",
success: function (data, textStatus) {
alert("success");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("error");
alert(textStatus);
alert(errorThrown.toString());
}
});
});
</script>
server code:
Response.ContentType ="application/json";
string json = "{"username":"test"}";// ,"content":"test"
Response.Write(json);
when i click the post request button the result is shown like this Invalid Json,the browser alert this.