Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6793039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:03:10+00:00 2026-05-26T18:03:10+00:00

I am developing a module which has a jQuery script with some AJAX code.

  • 0

I am developing a module which has a jQuery script with some AJAX code. The ajax code calls a php script located in the same location as the jQuery script.

My problem is, AJAX appends the domain name in front of the PHP script name and of course, my script does not exist at that location and so the process breaks.

The AJAX code is as follows:

    $(document).ready(
    function(){

        $.ajax({
          url: "/testscript.core.php",
          asych: false,
          success: function($data){
            $('textarea#edit-simplechat-messages').text( $data );
          }
        });

    }
);

And the following is the link that shows up in firebug:

http://testsite.co.uk/testscript.core.php

Again, the jQuery script and the php script are in the same directory.
I thought the forward slash before my php script name would eliminate the domain name but it did not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:03:11+00:00Added an answer on May 26, 2026 at 6:03 pm

    Use

    Drupal.settings.basePath
    
    url: Drupal.settings.basePath+'your file path',
    

    This link might be useful

    http://www.akchauhan.com/how-know-base-path-of-drupal-in-javascript/

    EDIT :

    Or you can use this approach if you are creating your own custom module then follow these steps

    1] First create your module, Here my module name is “mymodule”, So i created a file name mymodule.module

    <?php
    
    function mymodule_init() {
        drupal_add_js(drupal_get_path('module', 'mymodule') . '/mymodule.js');
        // this call my js file when module is initialized.
    }
    
    function mymodule_menu(){
        $items = array();
    
        $items['mypath'] = array(
            'title' => t('To get series of the selected brand'),
            'page callback' => 'mymodule_page',
            'page arguments' => array(1),
                 // get test_parameter from url, which is your first argument
                 //http://domain.com/mypath/test_parameter
                 // here mypath is arg(0), and test_parameter is arg(1)
            'access arguments' => array('access content'),
            'type' => MENU_CALLBACK,
        );
    
        return $items;
    }
    
    function mymodule_page($termID){
        return drupal_json(array('message'=> $itemID));
    }
    

    2] Secondly create js file with the same name so name it mymodule.js under the same module file.

    // $Id$
    
    Drupal.behaviors.mymodule = function (context) {
        var $basepath = Drupal.settings.basePath;
        $('selector').change(function(e){
            $.ajax({
                type: 'POST',
                url: $basepath+'mypath/test_parameter',
                        // test_parameter :value you are sending to you module.
                dataType:'json',
                cache:false,
                beforeSend:function(){              
    
                },
                success:function(data){
                    alert(data.message);
                },
                complete:function(){
    
                },
                error:function(xhr, status, error){
    
                }
            });
        });  
    }
    

    Notice in js file i have used mypath. your js file will call this path which is defined in the hook_menu().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a small part of a PHP application with some python code.
I'm developing an application which has a lot of text and also different modules
iam developing a module in Drupal, which needs to have a locking machanism, When
I'm testing my project installation script on CentOS5.5. My project need Date::Manip module which
I am currently developing a module for Apache 2/2.2 and need to perform some
I'm developing a module which alter display of add/edit node forms. I'm a beginner
I am in the middle of developing a Django application, which has quite complicated
I'm developing a PHP application which uses Twig (but that's unimportant) as the view
I am developing a part of a software which has two modules(mail and web-service).But
I am new to Joomla. I am developing a dynamic module which will display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.