Re: [xwiki-users] Javascript RESTful

2015-04-06 Thread Marius Dumitru Florea
You overcomplicate it by specifying all those optional parameters.
This works for me:

require(['jquery'], function($) {
  $.get(XWiki.contextPath + '/rest').done(function(data) {
console.log(data);
  });
});

Hope this helps,
Marius

On Sat, Feb 21, 2015 at 1:11 PM, Matthias Wegner mic.mat.weg...@web.de wrote:
 Hello,

 i like the REST-API and have a library in Java which works perfect. Now i
 want to use the RESTful API in Javascript. But i am new to javascript and
 tried a lot, but nothing seems to work. Is there a simple example in
 javascript with the rest-api?

 I don't get what i am doing wrong, because i am not good in javascript.

 I tried

 require(['jquery'], function ($) {
   $.ajax({
  accepts: {xml: 'text/xml', text: 'text/plain'},
  url: 'http://HOST/xwiki/rest',
 type: 'GET',
  dataType: 'xml',
 contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  converters: {'text xml': jQuery.parseXML},
  crossDomain: true,
  async: true,
  username: 'username',
  password: 'apassword',
  success: function(data){
 alert(Success: +JSON.stringify(data));
  },
 error: function(data){
 alert(Error: + JSON.stringify(data));
  }
   });
 });

 Also i tried

 var httpRequest = new XMLHttpRequest();
 httpRequest.open('PUT', 'http://HOST/xwiki/rest');
 httpRequest.setRequestHeader('Accept', 'application/xml');
 httpRequest.send( null );
 alert( JSON.stringify(httpRequest.responseText) );
 httpRequest.onreadystatechange = function(){
   if(this.readyState == 4){
if(this.status == 200){
  alert(this.responseText);
}
else{
  alert(this.statusText);
}
   }
 }

 I recognized a difference in ajax when i switched to jsonp because i tried
 on localhost. But anyway my example work when i use my server outside.

 Can you help me?

 Regards,
 Matthias



 --
 View this message in context: 
 http://xwiki.475771.n2.nabble.com/Javascript-RESTful-tp7594084.html
 Sent from the XWiki- Users mailing list archive at Nabble.com.
 ___
 users mailing list
 users@xwiki.org
 http://lists.xwiki.org/mailman/listinfo/users
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users


[xwiki-users] Javascript RESTful

2015-02-21 Thread Matthias Wegner
Hello,

i like the REST-API and have a library in Java which works perfect. Now i
want to use the RESTful API in Javascript. But i am new to javascript and
tried a lot, but nothing seems to work. Is there a simple example in
javascript with the rest-api?

I don't get what i am doing wrong, because i am not good in javascript.

I tried

require(['jquery'], function ($) {
  $.ajax({
 accepts: {xml: 'text/xml', text: 'text/plain'},
 url: 'http://HOST/xwiki/rest',
type: 'GET',
 dataType: 'xml',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
 converters: {'text xml': jQuery.parseXML},
 crossDomain: true,
 async: true,
 username: 'username',
 password: 'apassword',
 success: function(data){
alert(Success: +JSON.stringify(data));
 },
error: function(data){
alert(Error: + JSON.stringify(data));
 }
  });
});

Also i tried

var httpRequest = new XMLHttpRequest();
httpRequest.open('PUT', 'http://HOST/xwiki/rest');
httpRequest.setRequestHeader('Accept', 'application/xml'); 
httpRequest.send( null );
alert( JSON.stringify(httpRequest.responseText) );
httpRequest.onreadystatechange = function(){
  if(this.readyState == 4){
   if(this.status == 200){
 alert(this.responseText);
   }
   else{
 alert(this.statusText);
   }
  }
}

I recognized a difference in ajax when i switched to jsonp because i tried
on localhost. But anyway my example work when i use my server outside.

Can you help me?

Regards,
Matthias



--
View this message in context: 
http://xwiki.475771.n2.nabble.com/Javascript-RESTful-tp7594084.html
Sent from the XWiki- Users mailing list archive at Nabble.com.
___
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users