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 7188963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:12:01+00:00 2026-05-28T19:12:01+00:00

I have a strange issue with my code I can’t seem to figure out.

  • 0

I have a strange issue with my code I can’t seem to figure out. I’m relatively new to js and utilizing http requests to retrieve json data however I’ve been able to come up with code that works, for the most part.

Essentially the workflow is as follows: I have a user enter some form field values and select the submit button. Onsubmit the the apiCall() function is called which then calling the createXMLHttpRequestObject() and constructApiURL(searchtype) functions creates, populates, and sends the xmlHttpRequest Object via the proxy to the search api url. Once the result is returned the handleResults() function is called which then parses and displays the results in the apropriate div container using the handleResultsContainer() function.

Everything works when I step through the code via firebug. The object is created, sent via the proxy to the search api, the results are returned and displayed but once the focus returns to the function onsubmit(event) {callApi();} and the contents then clear!?! I don’t know if the page is reloaded or something else is going on.

Now if I change the initial trigger from a form submit to a button onclick it works without issues. The user selects the button, the search results are retrieved and displayed until the user selects the button again at which point the results are cleared and the new results are displayed. The problem is that I have to hard code the parameters I would normally be getting from the form.

Has anyone experienced this or sees something with how the code is being read by the browser that could cause this? My Pseudo code is below.

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<script type="text/javascript"> 
function createXMLHttpRequestObject() { 
-- code to create the XMLHttpRequestObject based on browser type --
} 

function constructApiURL(searchtype) { 
-- code to create the api url using the form values & proxy url --
} 

function handleResultsContainer () { 
-- code to create/remove search results display div
} 

function handleResults(jsndata) { 
-- code to parse and display results here --
} 

function callApi() { 
-- code to create XMLHttpRequestObject, populate it, and send it --
} 

</script> 
</head> 
<body>

<form id="basicform" name="mashsearch" onsubmit="callApi()"> 
     -- Code for user input fields which are then used by constructApiURL --
     <input type="submit" id="searchbtn" value="Search!"/> 
</form> 

//Div displaying a Search Results Loading… message which is hidden/displayed//
<div id='loadingDiv' style="display:none">Search Results Loading...</div> 

//Div used to display the search results
<div id='json'></div> 
</body> 
</html> 
  • 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-28T19:12:02+00:00Added an answer on May 28, 2026 at 7:12 pm

    Change your onsubmit to :

    onsubmit="callApi();return false;"
    

    Alternatively you could add return false to the bottom of your callApi() method and change your onsubmit to be onsubmit="return callApi()"

    If you do not the page will submit and reload as its normal behaviour would.

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

Sidebar

Related Questions

I'm having a strange issue that I can't seem to figure out. I tried
I have a strange issue from a client in that our code, which they
I'm having a strange issue here, i have this bit of code: <?php if
I seem to be facing a strange issue in SQL 2008. I have a
So I have some strange issue with nl2br so I have the following code:
I have a strange issue with my css navigation menu. The code is here:
I've been pulling my hair out over a strange issue... from what I can
I have a very strange issue, that I'm hoping someone here can help me
I seem to have run into a strange issue whereby a string reference is
I have a strange issue: I am using SPContext.Current.Web in a .aspx page, but

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.