I've implemented my module as follows:

<?php

function simpim_menu() {
  $items['simpim/check_messages'] = array(
    'page callback' => 'check_messages',
    'type' => MENU_CALLBACK,
  );
  $items['simpim/writemessage'] = array(
    'page callback' => 'writemessage',
    'type' => MENU_CALLBACK,
  );
  $items['simpim/get_message'] = array(
    'page callback' => 'get_message',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

?>

In my javascript file I have the following:


		xmlhttp=$.ajax({
			type: 'GET',
			url: '/sports/sites/all/modules/simpim/simpim/writemessage/',
			data: 'suid='+uid+'&sname='+uname+'&ruid='+partnerID+'&rname='+partner+'&msg='+sendText,
			success: function(msg){
				alert(msg);
			}
		 });
		 return false;
		});

I'm expecting Drupal to implement the 'writemessage' function as specified in the 'page callback' => 'writemessage', but this does not appear to be happening.

Is my implementation of this okay? Or is my grasp of the concepts of this way off?

my apache access.log has the following lines:

10.0.0.7 - - [17/Aug/2009:09:30:59 +0200] "GET /sports/sites/all/modules/simpim/simpim/check_messages?_=1250494232546&ruid=27 HTTP/1.1" 404 324 "http://bilbo/sports/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5"
10.0.0.7 - - [17/Aug/2009:09:31:03 +0200] "GET /sports/sites/all/modules/simpim/simpim/writemessage/?suid=1&sname=admin&ruid=27&rname=zed&msg=morning HTTP/1.1" 404 322 "http://bilbo/sports/?q=node/6" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.13) Gecko/2009073022 Firefox/3.0.13 (.NET CLR 3.5.30729)"

In this segment "GET /sports/sites/all/modules/simpim/simpim/writemessage/?suid=1&sname=admin&ruid=27&rname=zed&msg=morning HTTP/1.1" 404 the 404 seems to imply a 'File not found' error, but this may not necessarily be unexpected as the "/sports/sites/all/modules/simpim/simpim/writemessage/" file (or directory) does not exist.

Can anyone assist?

Comments

somes’s picture

Its so long since i've looked at page callbacks but in the javascript just use

url: '/sports/sites/all/modules/simpim/writemessage/'

davecoventry’s picture

Unfortunately no change.

10.0.0.5 - - [17/Aug/2009:17:46:20 +0200] "GET /sports/sites/all/modules/simpim/writemessage/?suid=27&sname=zed&ruid=1&rname=admin&msg=anybody%20there? HTTP/1.1" 404 317 "http://bilbo/sports/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5"
10.0.0.5 - - [17/Aug/2009:17:46:27 +0200] "GET /sports/sites/all/modules/simpim/check_messages?_=1250523952657&ruid=27 HTTP/1.1" 404 318 "http://bilbo/sports/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5"

As I understand it, if I put "http://bilbo/sports/sites/all/modules/simpim/writemessage/" I should get a blank page, but I get a 404.

ericduran’s picture

The right url is http://baseexample.com/simpim/writemessage

Also you need to implement the writemessage function

Eric

davecoventry’s picture

One thing that's encouraging is that it seems I am going in the right direction even if I am not actually on the right track.

However, I still have the same result:

10.0.0.5 - - [18/Aug/2009:08:50:31 +0200] "GET /sports/simpim/check_messages?_=1250578196281&ruid=3 HTTP/1.1" 404 309 "http://bilbo/sports/?q=node/6" "Opera/9.63 (Windows NT 5.1; U; en-GB) Presto/2.1.1"

10.0.0.5 - - [18/Aug/2009:08:50:40 +0200] "GET /sports/simpim/check_messages?_=1250578204919&ruid=1 HTTP/1.1" 404 309 "http://bilbo/sports/?q=admin/content/node" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.13) Gecko/2009073022 Firefox/3.0.13 (.NET CLR 3.5.30729)"

10.0.0.5 - - [18/Aug/2009:08:50:40 +0200] "GET /sports/simpim/writemessage/?suid=3&sname=davec&ruid=&rname=&msg=Hi%20there HTTP/1.1" 404 307 "http://bilbo/sports/?q=node/6" "Opera/9.63 (Windows NT 5.1; U; en-GB) Presto/2.1.1"

10.0.0.5 - - [18/Aug/2009:08:50:41 +0200] "GET /sports/?send=Hi+there HTTP/1.1" 200 2889 "http://bilbo/sports/?q=node/6" "Opera/9.63 (Windows NT 5.1; U; en-GB) Presto/2.1.1"

10.0.0.5 - - [18/Aug/2009:08:50:43 +0200] "GET /sports/misc/feed.png HTTP/1.1" 304 - "http://bilbo/sports/?send=Hi+there" "Opera/9.63 (Windows NT 5.1; U; en-GB) Presto/2.1.1"

10.0.0.5 - - [18/Aug/2009:08:50:50 +0200] "GET /sports/simpim/check_messages?_=1250578214929&ruid=1 HTTP/1.1" 404 309 "http://bilbo/sports/?q=admin/content/node" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.13) Gecko/2009073022 Firefox/3.0.13 (.NET CLR 3.5.30729)"

>Also you need to implement the writemessage function


function simpim_menu() {
  $items['simpim/check_messages'] = array(
  	'title' => 'Check Message',
  	'path' => 'simpim/check_messages',
    'page callback' => 'check_messages',
    'type' => MENU_CALLBACK,
  );
  $items['simpim/writemessage'] = array(
  	'title' => 'Write Messages',
  	'path' => 'simpim/writemessage',
    'page callback' => 'writemessage',
    'type' => MENU_CALLBACK,
  );
  $items['simpim/get_message'] = array(
  	'title' => 'Get Messages',
  	'path' => 'simpim/get_message',
    'page callback' => 'get_message',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function writemessage(){
	$suid=$_GET['suid'];
	$sname=$_GET['sname'];
	$ruid=$_GET['ruid'];
	$rname=$_GET['rname'];
	$msg=$_GET['msg'];
	$messageq=db_query('INSERT INTO {im_msg} (suid,sname,ruid,rname,msg,sent_time) VALUES("'.$suid.'","'.$sname.'","'.$ruid.'","'.$rname.'","'.$msg.'","'.date("Y-m-d H:i:s").'")');
}

davecoventry’s picture

I really cannot see what I'm doing wrong.

Everything I read tells me that this should work but it doesn't.

davecoventry’s picture

I think there must be something wrong with my Drupal installation.

I've just installed the IM instant messenger module http://drupal.org/project/im and this doesn't appear to work either.

The im_msg database is not written to and the apache access.log returns the following information:

10.0.0.3 - - [18/Aug/2009:12:44:01 +0200] "POST /sports/im/friendlist HTTP/1.1" 404 302 "http://bilbo/sports/?q=admin/build/block" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)"

10.0.0.3 - - [18/Aug/2009:12:44:04 +0200] "POST /sports/im/friendlist HTTP/1.1" 404 302 "http://bilbo/sports/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5"

10.0.0.3 - - [18/Aug/2009:12:44:11 +0200] "POST /sports/im/friendlist HTTP/1.1" 404 302 "http://bilbo/sports/?q=admin/build/block" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)"

10.0.0.3 - - [18/Aug/2009:12:44:14 +0200] "POST /sports/im/friendlist HTTP/1.1" 404 302 "http://bilbo/sports/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5"

10.0.0.3 - - [18/Aug/2009:12:44:21 +0200] "POST /sports/im/friendlist HTTP/1.1" 404 302 "http://bilbo/sports/?q=admin/build/block" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)"

10.0.0.3 - - [18/Aug/2009:12:44:24 +0200] "POST /sports/im/friendlist HTTP/1.1" 404 302 "http://bilbo/sports/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5"

10.0.0.3 - - [18/Aug/2009:12:44:25 +0200] "POST /sports/im/get_all_messages/1 HTTP/1.1" 404 308 "http://bilbo/sports/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5"

10.0.0.3 - - [18/Aug/2009:12:44:30 +0200] "GET /sports/im/send_msg/27/1/?msg=hi%20there&js=1 HTTP/1.1" 404 306 "http://bilbo/sports/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5"

10.0.0.3 - - [18/Aug/2009:12:44:31 +0200] "POST /sports/im/friendlist HTTP/1.1" 404 302 "http://bilbo/sports/?q=admin/build/block" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)"

10.0.0.3 - - [18/Aug/2009:12:44:34 +0200] "POST /sports/im/friendlist HTTP/1.1" 404 302 "http://bilbo/sports/" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.39 Safari/530.5"

beautifulmind’s picture

In Drupal, url means, the path, it does not include /sites/all/modules/mymodule/mymodule.module/mymenu

url: '/sports/sites/all/modules/simpim/simpim/writemessage/',

should be

url: 'simpim/writemessage',

Regards.

Regards.
🪷 Beautifulmind

davecoventry’s picture

Yes, I believe so.

I have since modified the javascript, but the results remain the same.

I'm tearing my hair out because AFAICT it *should* work, but doesn't.

beautifulmind’s picture

Have you cleared the cache after modifying the menu?

Regards.
🪷 Beautifulmind

davecoventry’s picture

Have you cleared the cache after modifying the menu?

Yes.

And run update.php and cron. And remove the module and reinstall it.

I get the same results.

davecoventry’s picture

As I suspected there appears to be something wrong with my Drupal install.

I have taken my scripts onto another server but am now gettin a 403 error.

192.168.37.43 - - [19/Aug/2009:01:25:37 -0700] "GET /drupal/simpim/writemessage?suid=1&sname=admin&ruid=3&rname=dc&msg=what? HTTP/1.1" 403 7705
< /blockquote>