+ Reply to Thread
Results 1 to 3 of 3

Thread: need ajax help

  1. #1
    Hosting Master johnwest is on a distinguished road
    Join Date
    May 2014
    Location
    India
    Posts
    159

    need ajax help

    I'm working in dhtml (html, CSS, JavaScript, and Perl) using the latest Apache / mod_perl server on Windows 10. I don't seem to be able to get ajax to work. I'm trying to 'get' a multiline file (directory and file name) out of a database location. I'm thinking that the response text will return a string of lines separated by new lines (\n). I've tried the w3 simplest approach, jquery, and d3. The w3 approach is below.

    Code:
    
    
    var mFn = document.forms[0]['thefdir'].value + 'Measures/all.mea?t=' + Math.random(); // Unique ID bypasses cache.

    var xhttp = new XMLHttpRequest();
    xhttp.open('GET', 'dog.txt', true);
    xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
    fieldName3.value = this.responseText;
    }
    };
    xhttp.send();

    Its executed onChange to a field on a form generated by a Perl CGI program. The fieldName3.value would be processed downstream in the JS. I've tried it with the fully qualified location (mFn) and a relative location (dog.txt) with 1 line in it. Neither worked. I don't know what directory the relative location resolves to. So I put a copy in the server root and the cgi-bin directories. It did not work. Nothing happens and no error information.

    Any help will be appreciated.

  2. #2
    Hosting Master smartbrian is on a distinguished road
    Join Date
    Oct 2014
    Location
    India
    Posts
    130
    What you posted is not jQuery it is simply Javascript. If you are using plain Javascript you may want to consider the Fetch api. One caveat is that it is not supported by IE.


    https://developer.mozilla.org/en-US/.../API/Fetch_API

  3. #3
    HWHT Addict rossmn is on a distinguished road
    Join Date
    Apr 2020
    Location
    Hyderabad
    Posts
    31
    Yes, the w3 example ( [w3schools.com ] ) is JavaScript. I have also tried jQuery and d3.


    W3 says that ajax is supported by all major browsers today and the example is what I would like to do. And it is their 1st and simplest example. They talk about Fetch as being a more modern approach, but indicate the above should be solid cross browser.


    Is there something wrong with the w3 approach? The example is an html file and my JavaScript is called in a Perl/CGI file. My JS is in the header. The w3 JS is in the body. Are these problems?


    I need a cross browser solution.

+ Reply to Thread

Similar Threads

  1. Where AJAX cannot be used?
    By designpluz in forum Programming Discussion
    Replies: 0
    Last Post: 05-25-2019, 05:21 AM
  2. What is Ajax?
    By designpluz in forum Programming Discussion
    Replies: 0
    Last Post: 05-25-2019, 05:00 AM
  3. What's AJAX ?
    By sunled in forum Programming Discussion
    Replies: 1
    Last Post: 08-23-2018, 03:57 AM
  4. Should I consider AJAX?
    By sunled in forum Programming Discussion
    Replies: 0
    Last Post: 07-27-2018, 04:43 AM
  5. What is Ajax in ASP.NET?
    By sunled in forum Programming Discussion
    Replies: 0
    Last Post: 06-06-2018, 09:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts