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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:21:28+00:00 2026-06-05T20:21:28+00:00

here is my original function. it works perfectly, I just want to compress it

  • 0

here is my original function. it works perfectly, I just want to compress it a bit:

 <script type='text/javascript'>
function searchmusic(){
var ajaxRequest;  

try{
    ajaxRequest = new XMLHttpRequest();
} catch (e){
    try{
        ajaxRequest = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject('Microsoft.XMLHTTP');
        } catch (e){
            alert('Your browser broke!');
            return false;
        }
    }
}
ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
        var ajaxDisplay = document.getElementById('searchresults');
        ajaxDisplay.innerHTML = ajaxRequest.responseText;

    }
}
var search = document.getElementById('search').value;
var params = 'search=' + search;
ajaxRequest.open('POST', 'getsearch.php', true);  
ajaxRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
ajaxRequest.send(params);

}
</script>

I am trying to compress this function a bit, so i have tried to duplicate it using jQuery:

 <script>
 function searchmusic(){
 var search = document.getElementById('search').value;
 $.ajax({
type: 'POST',
url: getsearch.php,
async: true,
data: 'search=' + search,
success: function(data) {
$('#searchresults').load(data);
 }
 });
 }
</script>

However, I can not get this function to work properly. Could someone please tell me where I have made the mistake, and why this function is not working, or it could be that this new function can not function as my original one did. I don’t know, but any help would be greatly appreciated, thanks!

  • 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-06-05T20:21:29+00:00Added an answer on June 5, 2026 at 8:21 pm
    url: getsearch.php,
    

    should be

    url: 'getsearch.php',
    

    and

    success: function(data) {
        $('#searchresults').load(data);
    }
    

    should be

    success: function(data) {
        $('#searchresults').html(data);
    }
    

    And also var search = document.getElementById('search').value; is ok but as because you are using jQuery so you can use var search = $('#search').val() instead and by default async is true so you could ommit it and also $.ajax could be $.post so you can remove type: 'POST' too.

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

Sidebar

Related Questions

I'm trying to parallelize a convolution function in C. Here's the original function which
Let's say I have some original text: here is some text that has a
I'm having trouble understanding how QGraphicsItemAnimation's setScaleAt function works. Here's the code I'm using:
I want to send var-args of a function to a macro, still as var-args.
The script below works perfectly. However, it's not quite what I'm trying to achieve.
Here is original Query :, it generates o/p with two columns name (label, count)
Refer original post here for a reference to the original issue. What plugin should
here is the original code: public static int getInt () { Scanner in =
Ok, here was my original question; Table one contains ID|Name 1 Mary 2 John
This question is sort of a follow-up to my original question here . Let's

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.