Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I would like to call a webservice through jquery using mvc3 application.

Here how could I pass the username and password for credential

Hope some help


Thanks & Regards,
Soumya
Posted

Try this.Please make sure that you must add jQueryplugin in your page

JavaScript
$.ajax({
     url:webserviceUrl,
     type: "POST", //This is what you should chage
     dataType: "application/json; charset=utf-8",
     username: "user", // 
     password: "pwd",
     processData: false,
     contentType: "application/json",
     success: function () {
         alert("success");
     },
     error: function (xhr, ajaxOptions, thrownError) { 
         alert(xhr.status);
         alert(xhr.responseText);
     },
 });


If you need more information go through this link
http://blog.coreycoogan.com/2010/12/17/calling-asp-net-web-service-asmx-from-jquery/[^]
Hope this helps
 
Share this answer
 
First of all, this has little to do with MVC3.
Depends on many things, especially the authentication. You can[^] consume SOAP web services from ajax. You could pass credentials too (ntlm/kerberos should be transparent), but that raises several security issues, since you should never store plain text (or even digested) credentials on client side.
I suggest you move this functionality on server side and present this to the client under the cloak of the regular normal services provided by your server application. This is the only reliable approach if clients are spread over the internet, and there is no guarantee that the client will be able to consume the third party service in a reliable manner.
 
Share this answer
 
Hello

Try to do this


function getMyObject(onSuccess) {
$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: "/JsonService/MyJsonMethod",
data: '{"id":"123456", "title":"object title"}',
beforeSend: function(xhr) {
//May need to use "Authorization" instead
xhr.setRequestHeader("Authentication",
"Basic " + encodeBase64(username + ":" + password)
dataType: "json",
success: onSuccess
});
}

It will help u..
 
Share this answer
 

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