Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old 10-28-2007, 09:57 AM
Zimlet Guru & Moderator
 
Posts: 467
Default

Quote:
Originally Posted by ordex View Post
i got the same problem...can someone help me?
thank's a lot
If you post enough of a snippet to try and debug the code, I will take a whack at it this afternoon.
Reply With Quote
  #12 (permalink)  
Old 10-28-2007, 10:45 AM
Starter Member
 
Posts: 2
Exclamation

I have a dialog contenent a div

Code:
div.innerHTML =
		[ "<table><tbody>",
		  "<tr>",
		    "<td align='center'><label for='", toId, "'>Num: <input autocomplete='on' style='width: 21em' type='text' id='", toId, "' value='", toValue, "'/>",
		    "</td>",
		  "</tr>",
		  "<tr>",
		"<td colspan='2' align='center'>",
		"<textarea rows='10' cols='100' style='width: 25em' name='testo' id='", bodyId, "'>", bodyValue, "</textarea>",
                "<br>",
		"<form name='uploadForm' id='uploadForm' method='post' enctype='multipart/form-data' action='/service/upload?fmt=raw'>",
			"<input type='file' name='attach' />",
			"<input type='hidden' name='requestId' value='firstAttach' />",
		"</form>",
		"</td>",
		"</tr>",
		"<tr></tr>",
		"</tbody></table>" ].join("");
        el.appendChild(div);

	var dialog_args = {
		title : "Zimlet",
		view  : view
	};
	var dlg = this._createDialog(dialog_args);
	dlg.popup();
On click on the OK button a function is called:
Code:
        var form = document.getElementById("uploadForm");
	var iframe = document.createElement("iframe");
	var view = new DwtComposite(this.getShell());
	view.getHtmlElement().appendChild(iframe);
		
	var post = new AjxPost(iframe);
	var callback = new AjxCallback(this, this._resultCallbackAlert);
	post.execute(callback, form);
But callback is not called and a new window is opened with the result ouput in it.

I also tried in this way, but it doesn't work
Code:
document.body.appendChild(el);
Thank's again

Last edited by ordex; 10-28-2007 at 10:58 AM..
Reply With Quote
  #13 (permalink)  
Old 08-28-2008, 02:27 PM
Intermediate Member
 
Posts: 17
Default AjxPost Method

I notice that it's been over a year and a half now, and no one has answered Jiggy's question.
Is there some sample code somewhere that shows how to use AjxPost to post variables to another website or web service?
I have not found any sample Zimlets that use AjxPost.
Reply With Quote
  #14 (permalink)  
Old 01-28-2009, 01:30 AM
Junior Member
 
Posts: 7
Default

This may not be a "perfect" solution. It is possible to GET data with AjxRpc.invoke, but since a regular AJAX request cannot go to other webservers (it's a browser restriction), I prefer to use a proxy jsp that receives the data from the client, passes it on to the external service, gets a result back and sends it to the client.

Something like this:

Code:
proxy.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<%@page import="java.util.*"%>

<%
List<String> allowedDomains=new ArrayList<String>();
allowedDomains.add("www.zimbra.com"); // external domain you want to call, without prefix, and you may add several domains by duplicating the line

    try {
    URL url = new URL(URLDecoder.decode(request.getParameter("url")));

    if (!allowedDomains.contains(url.getHost()))
        throw new Exception("Invalid hostname");

    InputStream is = url.openStream();
    BufferedReader r = new BufferedReader(new InputStreamReader(is));
    StringBuffer buf = new StringBuffer();
    String line;
    while ((line = r.readLine()) != null) {
         buf.append(line);
    }
    r.close();
    is.close();

    out.print(buf.toString());

} catch (Exception ex) {
}
%>
Then call this in javascript:
Code:
	var url=this.getResource('proxy.jsp'); // "this" being the handler object of the zimlet
	var str=escape("http://zimbra.com"+"?"+"param1=value1&param2=value2");// Create the request string
	var reqHeader = {"Content-Type":"application/x-www-form-urlencoded"};
	AjxRpc.invoke("url="+str, url, reqHeader, new AjxCallback(this, this.callbackfunction));
This code is for GET requests, but a little tweaking might just make it POST as well. The org.apache.commons.httpclient.methods.PostMethod class is a good place to start if you must POST the data. That'll of course be used in the proxy jsp.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.