Using $Ajax to save filename to a scaffold

Asked

Viewed 19 times

0

I’ve been working on it but I can’t solve my problem. I have a JS code that through an input I can access a txt file and get its name. I also created a History scaffold so I can store that name.

if (passAll === true) {
   var fullPath = document.getElementById('file').value;
     if (fullPath) {
       var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
       var filename = fullPath.substring(startIndex);
         if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0) {
            filename = filename.substring(1);
         }
     alert(filename);
     }
}

I got an idea to use Ajax to, using the POST method, send this filename directly to the creation URL of my scaffold so I wouldn’t need to type the filename, which would be the normal way, and save automatically (Somehow, I’d appreciate it if you could explain to me how I could do this).

My big problem is how to use Ajax and where to use it in my JS? How?

I don’t know what else to add here, I believe that every scaffold created is the same, so I will not put my scaffold.

  • I do not understand the negative vote, I believed my question was clear, you may think that this question is not useful for you but I have a problem and need help

  • 1

    How to use Ajax: vanilla and jquery. Automatically save you do to the requested page.

  • That’s exactly what I’m not getting, could you show me using my example?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.