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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:44:21+00:00 2026-06-06T17:44:21+00:00

Though I’ve programming experience, am completely new to GS, JS, or anything related to

  • 0

Though I’ve programming experience, am completely new to GS, JS, or anything related to UI.

Scenario: Making an AJAX call from Greasemonkey script to a Servlet

Greasemonkey/JS Code:

function getResultsData(query){
alert("Getting the Data");
$.ajax( 
    {
    cache: false,   
    data: {"q":query},      
    dataType:"text",
    url: "http://myserver.com:8000/search?",
    success: processData        
    }); //end of $.ajax }

function processData(data){
alert("Got the data");
var myResultDiv = document.getElementById("searchRes");
myResultDiv.innerHTML = data; }

Servlet Code:

        System.out.println("-----------This is an AJAX call------------------");
        //Commented the original logic
        resp.setContentType("text/plain");
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().write("Text from Servlet");

Problem:

  • GS/JS code works perfectly if the url (in $.ajax) is some other existing API. Response reflects in the UI

  • However, when I give my server’s url, I can observe in the Firebug.Console that there’s no http response for that call but the status says 200 OK with the whole entry turned ‘RED’.

  • When I test the url copied from Firebug’s ‘http call entry’, it’s working perfectly as I can see the response ‘Text from Servlet’ on the new tab.

Can someone please help.

NOTE Website on which greasemonkey runs, and my server belong to same domain, i.e.

Greasemonkey website: wwww.example.com

My server: http://www.myserver.example.com

  • 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-06T17:44:23+00:00Added an answer on June 6, 2026 at 5:44 pm

    Thanks to @mattedgod. His comment triggered me to research more and I found the answer.

    Add the following snippet to make it work.

    response.setHeader("Access-Control-Allow-Origin", "*");
    

    Surprisingly, it doesn’t work if I explicitly specify my own server’s full http address in the header. I yet to find out why.

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

Sidebar

Related Questions

Though the question is generic, I would mention the scenario which sparked the query.
Though it's on the edge of programming questions, I think this is still relevant
Though the title says everything, I want to let you know the particular scenario
Though I come from a purely PHP background on the web development side of
Though $.ajax() can be used to do ajax things, I don't think its fit
Though there can be many but as i am very new to python so
Though , PreparedStatement can do everything i.e DDL ,DML related queries with better performance
Even though my phpinfo() shows my DOM as enabled, when I try to call
Though I use CouchDB-specific JQuery verison, the problem can appear to be not related
Though standard doesn't guarantee the thread-safety for new , most of the multi-threading operating

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.