Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Stuart Murry
JQuery Login using JSON
March 29, 2013 11:33 AM
Answer

Stuart Murry

Rank: New Member

Posts: 4

Join Date: March 12, 2013

Recent Posts

I'm using 6.1.1ga, Liferay IDE and Service Builder.

 1
 2function getServiceUrl(event) {
 3       
 4             var username='stu@liferay.com';
 5             var password='password';
 6             var baseurl = 'liferay.com:8181/<build.xml name>/api/jsonws/' + event;
 7             var url = 'http://' + username + ':' + password + '@' + baseurl + '?callback=?';
 8             return url;
 9             
10    }
11   
12    $(document).ready(function() {
13       
14        var url = getServiceUrl('events/test');
15            
16          $("#start").click(function() {
17             $.ajax({
18                  type: "GET",
19                  url: url,
20                  dataType: 'jsonp',
21                  success: function(data){
22                    console.log(data);
23                  },
24                  error: function(xhr){
25                    alert("Error");
26                }
27              });
28            });
29    });



I've starting to build JSON web services successfully and I was able to view these web services by:

1http://stu@liferay.com:password@liferay.com/<Portlet-Name>/api/jsonws

However, Firefox keeps displaying an empty dialog box saying "portal realm authentication" and asking me to do a basic authentication. I would press enter without typing username and password and it would go away and the ajax queries would start returning data. I wrote a mobile app using JQuery mobile and Phonegap and plan on deploying it using Phonegap Build by Adobe. Step one would be accessing the data I created in Liferay via JSON webservices.
My question is how do I do a simple log-in/authentication much like an html form would do using j_username and j_password?

Thanks,
Stuart
Bruno Farache
RE: JQuery Login using JSON
September 20, 2013 4:43 AM
Answer

Bruno Farache

LIFERAY STAFF

Rank: Expert

Posts: 446

Join Date: May 14, 2007

Recent Posts

Stuart, this question is very old and I just saw it today, sorry about that, but my answer may help someone in the future.

Firefox has some issues when you use "@" in the authentication part of the URL, you need to encode the username first, something like that:

var url = 'http://' + encodeURIComponent(username) + ':' + password + '@' + baseurl + '?callback=?';