It looks like you're trying to use standard XmlHttpRequest Ajax
techniques, which will not work in OpenSocial applications.  (The
reason for this is because the gadget will run on a different domain
from your PHP script, and web browsers limit these types of
connections to same domain transfers only).

You should look into the gadgets.io.makeRequest function to pass data
to remote servers.  Here's an article describing what you can do with
this function:
http://wiki.opensocial.org/index.php?title=Introduction_to_makeRequest

~Arne


On Jun 18, 11:28 am, Prakhar <hiprak...@gmail.com> wrote:
> Hi friends!
>
> Hope you are keeping up a good health and life.
>
> I am trying to build an os app where theres a page where i need to
> send the form data to a php page using the httprequest method. I have
> juxtaposed the code here. Please try and have a look and tell me how
> to do it.
>
> [CODE]
>
> function writearticle() //the function that is called when the user
> clicks on "write article"
> {
> document.getElementById('Right_Panel').innerHTML="<form>     <table style=
> \"width: 100%\">   <tr>                      <td align=\"right\" 
> style=\"width: 116px
> \">Title:</td>                    <td><input name=\"title\" style=\"width: 
> 530px\" type=
> \"text\" />&nbsp;</td>           </tr>             <tr>                      
> <td align=\"right\" style=
> \"width: 116px\">Category id:</td>                   <td><input 
> name=\"category_id\"
> type=\"text\" /></td>                </tr>             <tr>                   
>    <td align=\"right\" style=
> \"width: 116px\">Aricle Text:</td>                   <td><textarea 
> name=\"content\"
> style=\"width: 532px; height: 401px\"></textarea>&nbsp;</td>               
> </tr>
> <tr>                      <td align=\"right\" style=\"width: 
> 116px\">&nbsp;</td>
> <td><input name=\"Submit1\" type=\"submit\" value=\"submit\" />&nbsp;</
> td>          </tr>     </table></form>"
>
> var httpRequest;
>
>         var type = arguments[0];  // get type of call
>
>         if (window.XMLHttpRequest)
>         { // Mozilla, Safari, ...
>             httpRequest = new XMLHttpRequest();
>             if (httpRequest.overrideMimeType) {
>                 httpRequest.overrideMimeType('text/xml');
>             }
>         }
>
>         else if (window.ActiveXObject)
>         { // IE
>             try {
>                 httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
>                 }
>             catch (e)
>             {
>                 try {
>                     httpRequest = new ActiveXObject
> ("Microsoft.XMLHTTP");
>                         }
>                 catch (e) {}
>             }
>         }
>
>         if (!httpRequest)
>         {
>             alert('Giving up :( please use IE or Mozilla');
>             return false;
>         }
>
>         // Set data to submit to server, based on the type of the
> action
>
>         var data;
>         if (type == 0)
>         {
>             data = 'type=word';
>             //alert(data);
>         }
>
>         httpRequest.open('POST', 'getarticle.php', true);
>         httpRequest.setRequestHeader('Content-Type', 'application/x-
> www-form-urlencoded');
>
>         httpRequest.onreadystatechange = function()
>                 {
>                         //alert("In httprequest block");
>                         //alert(httpRequest.responseText);
>                         //word = httpRequest.responseText;
>                         if (httpRequest.readyState == 4)
>                         {
>                                 if (httpRequest.status == 200)
>                                 {
>                                         return
> httpRequest.responseText;
>                                 }
>                         }
>                         alert(httpRequest.responseText);
>                 };
>         //else
>                                 //other requests
>
>         httpRequest.send(data);
>
> }
>
> [/CODE]
>
> ---------------------------------------------------------------------------------------------------------
> the code from 'setarticle.php' is
>
> [PHP]
>
> <?php
> include("opensocial.php");
> connect();
> print "hello";
> //$user_id=$_GET['user_id'];
> $content=$_GET['content'];
> $category_id=$_GET['category_id'];
> $title=$_GET['title'];
> //print $user_id . $content . $category_id;
> $result = setarticle($user_id,$content,$category_id,$title);
> //todo: check the result here
> ?>
>
> [/PHP]
>
> -----------------------------------------------------------------------------------------------------------------------------
> the problem the contents of "setarticle.php" get displayed in a alert
> box and nothing happens. I simply want that when the user clicks on
> the "submit" button, the contents from the text boxes as shown in
> getElementById thing are transfered to the setarticle.php page. The
> setarticle.php is working fine and is able to post contents to
> database when tried from a simple <form action > thing.
>
> Any help would be deeply appreciated!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"OpenSocial Application Development" group.
To post to this group, send email to opensocial-api@googlegroups.com
To unsubscribe from this group, send email to 
opensocial-api+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/opensocial-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to