简体   繁体   中英

How to navigate to another file using jquery or javascript?

I have the code like given below

<div id="content">
<h1>SITE INFORMATION!</h1>
<div id="taskList"></div>
<label for="taskName">Enter a site name:</label>
<input type="text" id="taskName"></input>
<label id="error" style="display:none"></label>
<label for="taskName">Enter a site no:</label>
<input type="text" id="taskName"></input>
<label id="error" style="display:none"></label>
<input type="submit" id="submit" value="Submit" data-theme="b"></input>
<button type="next" onclick="go()">next</button>
<script> 
    function go(){
        // Some code  
    } 
 </script> 
 </div>

But the problem is on clicking the next button i need to display another file(probably .vm file) located in my system folder. The file will be in my local system and when i am accessing by browser the above page that file needs to be displayed.

Can you please help me out in doing this

You don't need jQuery for that, simple window.location code will do it, eg:

window.location.href = myUrl;

window.location.href = "/somewhere/else";

Define "system folder"?

Technically, you can do this by using onclick="window.location.href='/path/to/some/file'" but that won't work if the file you're trying to get to is higher than your web root.

If you need to send the information requested in this page to the next page the easiest way would be to use a traditional HTML form:

<form method="POST" action="./next.html">
  <label for="taskName">Enter a site name:</label>
  <input type="text" id="taskName"></input>
  <label id="error" style="display:none"></label>
  <label for="taskName">Enter a site no:</label>
  <input type="text" id="taskName"></input>
  <label id="error" style="display:none"></label>
  <input type="submit" id="submit" value="Submit" data-theme="b"></input>
  <input type="submit" name="submit" />
</form>

Notice that your <button type="next" /> is now <input type="submit" /> hope it helps.

You can use jQuery load:

$( 'target' ).load( "you_file_path", function() {
    alert( "Load was performed." );
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM