[support] I would like to be able within a Drupal module's hook do an ajax call to a Java Servlet.
John Mitchell
mitchelljj98 at gmail.com
Thu Apr 15 17:11:04 UTC 2010
I get the following error within firebug on firefox:
uncaught exception: [Exception... "Component returned failure code:
0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult:
"0x80004005 (NS_ERROR_FAILURE)" location: "JS frame ::
http://localhost/drupal/index.php?q=node :: <TOP_LEVEL> :: line 58"
data: no]
The above error appears to be for:
drupal_add_js('xmlHttpReq.send(null)', 'inline');
When trying to run the following ajax code:
function goodreads_block($op='list' , $delta=0, $edit=array()) {
drupal_add_js('var xmlHttpReq = new XMLHttpRequest()', 'inline');
drupal_add_js('var url = "https://localhost/midcollection"', 'inline');
drupal_add_js('xmlHttpReq.open("post", url, false)', 'inline');
drupal_add_js('xmlHttpReq.send(null)', 'inline');
drupal_add_js('var responseText = xmlHttpReq.responseText', 'inline');
}
John
On 4/15/10, Jamie Holly <hovercrafter at earthlink.net> wrote:
> Look at drupal_add_js
>
> http://api.drupal.org/api/function/drupal_add_js
>
>
> Jamie Holly
> http://www.intoxination.net
> http://www.hollyit.net
>
>
> On 4/15/2010 6:51 AM, John Mitchell wrote:
>> I am trying to make this as simple as possible:
>>
>> As an example (listed below) I have a javascript ajax call to a java
>> servlet within my existing Apache Tomcat web application not Drupal.
>> All that would need to be modified would that the URL have to be the
>> full path.
>>
>> Is their a way within Drupal to embed a javascript call similar to the
>> one listed below?
>>
>> Thanks,
>>
>> John
>>
>> <script type = "text/javascript">
>> function download(link){
>> var email = document.getElementById('email');
>> var xmlHttpReq = new XMLHttpRequest();
>> var url = 'ecommerce?command=serve&name=' + link + '&email=' +
>> email.value;
>> xmlHttpReq.open('post', url, true);
>> xmlHttpReq.onreadystatechange = function() {
>> if (xmlHttpReq.readyState != 4) {
>> return;
>> }
>> else {
>> var responseText = xmlHttpReq.responseText;
>> return false;
>> }
>> }
>> xmlHttpReq.send(null);
>> }
>> </script>
>>
>>
>>
>> On 4/15/10, sumeet pareek<positivecharge at gmail.com> wrote:
>> > Does this help - http://drupal.org/node/44895 ?
>> >
>> > On Thu, Apr 15, 2010 at 3:43 PM, John Mitchell<mitchelljj98 at gmail.com>
>> > wrote:
>> >> Let me rephrase my question: I currently within the same server have
>> >> Apache/Drupal and Apache Tomcat/Java. I would like to be able within
>> >> a Drupal module's hook do an ajax call to a Java Servlet.
>> >>
>> >> How would I do this within Drupal version 6?
>> >>
>> >> For future reference how would I do this within Drupal version 7?
>> >>
>> >> Thanks,
>> >>
>> >> John
>> >>
>> >> On 4/14/10, Seth Freach<sfreach at gmail.com> wrote:
>> >>> John Mitchell wrote:
>> >>>> How would I do an ajax call within my own custom module?
>> >>>>
>> >>>> Thanks,
>> >>>>
>> >>>> John
>> >>>>
>> >>>>
>> >>> You will probably need 2 menu items:
>> >>> - The first to define the page that will be the ajax client. Ie,
>> >>> the
>> >>> url of the page that this all happens on, a regular drupal page that
>> >>> has
>> >>> called drupal_add_js() to add some JS code that will do a
>> >>> $.ajax({...});
>> >>> call (or other jquery asynchronous call). This menu item might not
>> >>> be
>> >>> needed though if the JS is added in a block, or inserted via
>> >>> hook_form_alter or hook_nodeapi, etc.
>> >>> - The second menu item will define the ajax server. It should be
>> >>> 'type'=>MENU_CALLBACK and have the appropriate access checks defined
>> >>> as
>> >>> well. The callback function associated with this path should,
>> >>> instead
>> >>> of returning themed output, end with: drupal_json(array(...));
>> >>> exit();
>> >>> where the array(...) is an associative array that you want to hand
>> >>> back
>> >>> to the calling page in JSON format.
>> >>>
>> >>> If you're doing this for D7, look at:
>> >>>
>> >>> http://api.drupal.org/api/drupal/developer--examples--ajax_example--ajax_example.module/7
>> >>>
>> >>> Seth
>> >>> --
>> >>> [ Drupal support list | http://lists.drupal.org/ ]
>> >>>
>> >>
>> >>
>> >> --
>> >> John J. Mitchell
>> >> --
>> >> [ Drupal support list | http://lists.drupal.org/ ]
>> >>
>> >
>> >
>> >
>> > --
>> > Cheers
>> > Sumeet Pareek
>> > --
>> > [ Drupal support list | http://lists.drupal.org/ ]
>> >
>>
>>
>>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
--
John J. Mitchell
More information about the support
mailing list