Click here to Skip to main content
16,015,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use ajax to call my web services. Already i have deployed my web-service in my virtual machine.

URL:

http://www.lumiin.ch:8080/lumiin-service/lumiin/control/vprospects

Try this URL with Rest client Jar

Method = GET
Key = accept
value = Application/json

**My Code below**



$.ajax({
type: "GET", //GET or POST or PUT or DELETE verb
url: "http://www.lumiin.ch:8080/lumiin-service/lumiin/control/vprospects", // Location of the service
data: "", //Data sent to server
contentType: "application/json", // content type sent to server
dataType: "json", //Expected data format from server
processdata: true, //True or False
success: function (data) {//On Successfull service call

var result = json.name;
alert("result===" + result);
$("#dvAjax").html(result);
},
error: ServiceFailed// When Service call fails
});


return false;
});

});

But I am getting no response from the above code. Please help me out in this.

Regd's Karthick
Posted

Nellam Chandra

No, I have tried at my end but getting error due to cross domain call error. Any idea about this

Regards
Karthick
 
Share this answer
 
do it on a test page first

step1: add web reference of ur service to ur project

step:2 in javascript page

$(document).ready(function(){
$('#btnTest2').click
(
function ()
{

var value = "2";
$.ajax (
{
type: "POST",
url: "Liveuse_oftemplate.aspx/MethodWithNumericParameter",
data: "{'strParam':" +value+",'secondparam':3}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg)
{
alert(msg.d);

},
error: function (x, e)
{
alert("The call to the server side failed. " + x.responseText);
}
}
);
return false;
}
);

});





step:3 in serveice


[WebMethod]
public static string MethodWithNumericParameter(string strParam, string secondparam)
{

return "Parameter sent to server from client side is " + strParam + " second param" + secondparam;
}
 
Share this answer
 
Comments
Karthick88it 20-Nov-12 2:17am    
After trying out this i am getting an error in my console as
ReferenceError: json is not defined
var result = json.name;

Any idea on this
NAPorwal(8015059) 21-Nov-12 1:29am    
Have u solved ur problem?
NAPorwal(8015059) 21-Nov-12 4:49am    
kartick, do u want to retrieve name from json using ?
var result = json.name;

then do it like

alert($.toJSON(data.d))

first alert data value and see if it is working then retrieve json.name value and don't forget to put reference of jquery.json-2.2.min.js in ur head tag
u can download it from

http://code.google.com/p/jquery-json/downloads/detail?name=jquery.json-2.2.min.js&can=2&q=

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900