1

Normally, I love drupal and generally I do, but I want to know why it makes coding in JavaScript so hard?

You see, I'm porting an existing page with an AJAX user interface into drupal. I would like to keep it AJAX but at the minute I can't see how - I can't even get a simple alert to work!

A quick google search made me find out 2 things. 1) I need help from someone 2) because drupal has a wired way of handling javascript due to it being a CMS.

All my script does is add to inputs to a mysql database in the following format, returning an error if the entry is alreading in the database: input1=input2. So if somebody could start me off with JavaScript in drupal; maybe give me a mysql example script (using AJAX), i'd be very grateful!

Thanks in advance,

Andy

PS Googling did reveal some example scripts but I had 2 problems with them. 1) I didn't quite get them 2) due to the fact they were for modules. I need to create a page with an AJAX interface on, not a module!

5
  • 1
    We'd need to see the code you're trying to implement. Also, modules are often used to create pages in the system. Take a closer look at the tutorials. Commented Dec 23, 2010 at 15:17
  • Ah hah, It's just 'clicked' what you and andre have said about using modules. Use a module to replace the page! I'll look in to this, but meanwhile please still help me! :) Commented Dec 23, 2010 at 15:32
  • By the way, you asked for a closer look at my code; that's a bit hard due to privacy and all that. It's only the standard ajax script though, just look on w3schools or something! And I start the javascript function <script type="text/javascript"> as normal, like I think it says on w3schools! Commented Dec 23, 2010 at 15:54
  • There's no such thing as "the standard AJAX script." AJAX is a general technology that can be used for a lot of different things. There are also several ways to use JS and AJAX in Drupal. Without more details on what you're trying to do, this question is too vague to answer. Commented Dec 23, 2010 at 21:23
  • Okay, I understand but as I've said. I figured out what was going wrong and now everythings working perfectly - all I needed to do was add langauge="javascript" to the script tag! Thanks anyway though! Commented Dec 24, 2010 at 10:27

1 Answer 1

2

Maybe the solution to your problem IS a module.

Other than that, the only thing I can think of is: JavaScript is parsed out of your "page node" (I suppose that's what you mean by creating a "page") due to the content-type settings...

One thing you can do is to create a content-type where you can insert plain-text and hence execute javascript, php, whatever... Creating this kind of content-type, of course has security risks, depending on how you use it and who has permissions to use it...

Update Take a look at this link and see if it helps http://groups.drupal.org/node/41866#comment-114744

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your answer andre matos! I'll have to have a look at modules again but I had a look before I couldn't see anything. The problem with me is if it's not blindingly obvious and I can't find a solution regarding that module with in 30 mins, i'll go on to the next module! :p As for the content creation thing, I created a new content type just for coding so my WYSIWYG editor didn't get in the way but I'm not exactly sure what it's classed as!
Hmm... In fact when I mentioned that your solution could be a module, I was thinking in actually coding one for your specific need. It's not hard if you know the basics but it can be a little bit overwhelming to someone with no experience... Updated my answer!
OMG, i'm not sure - but I think I may have found the solution to my problem! I haven't tested it properly yet with AJAX but I've tested it with a simple JS function that wasn't working before! It's so simple though, I just forgot to add the langauge attribute in the script tag!!! But thank you anyway for your answers, much appriciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.