Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: How to submit zimlet form data using POST request method....??

  1. #11
    JoshuaPrismon is offline Zimlet Guru & Moderator
    Join Date
    Nov 2005
    Posts
    477
    Rep Power
    9

    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.

  2. #12
    ordex is offline Starter Member
    Join Date
    Aug 2007
    Posts
    2
    Rep Power
    7

    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 09:58 AM.

  3. #13
    DarthJader is offline Intermediate Member
    Join Date
    May 2008
    Posts
    17
    Rep Power
    7

    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.

  4. #14
    Lapeth is offline Junior Member
    Join Date
    Jan 2009
    Location
    Denmark
    Posts
    7
    Rep Power
    6

    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:
    
    <&#37;@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.

Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 21
    Last Post: 02-04-2010, 10:06 AM
  2. zmprov mc default zimbraFeatureNotebookEnabled TRUE
    By nbhanji in forum Installation
    Replies: 11
    Last Post: 04-29-2008, 10:39 AM
  3. Replies: 5
    Last Post: 01-11-2008, 05:34 AM
  4. Replies: 13
    Last Post: 07-20-2007, 03:21 AM
  5. Post instsallation problems
    By Assaf in forum Installation
    Replies: 14
    Last Post: 01-29-2007, 11:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •