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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:01:14+00:00 2026-05-26T11:01:14+00:00

OK, I have this piece of code, var record = new Object(); //var aData

  • 0

OK, I have this piece of code,

var record = new Object(); //var aData = {};でもOK  
record["deviceID"] = "123456"; //aData["name"] = "hoge"でもoK  
$.getJSON("http://192.168.2.10:8080/commapi/comaction/init", {record: JSON.stringify(record)},
function(objRes){  
    alert(objRes["response"]); //objRes["country"]でもok  
}); 

I just made a simple servlet that simply replies back the deviceID I put. But my problem is there is an error like

XMLHttpRequest cannot load http://192.168.2.10:8080/commapi/comaction/init?record=%7B%22deviceID%22%3A%22123456%22%7D. Origin file:// is not allowed by Access-Control-Allow-Origin.

how can I fix this? Thank you!

UPDATED SCRIPT
I tried using the JSONP, and my resulting script looks like this

$(document).ready(function() {
  $("#ui-2").click(function(){
      getJSON("http://192.168.2.143:8080/commapi/comaction/init?record=%7B%  22deviceID%22%3A%22123456%22%7D&callback=loaded"); 
  });
};


function getJSON(url){
var s = document.createElement('script');
  s.setAttribute('src',url);
  document.getElementsByTagName('head')[0].appendChild(s);

  // Loading ..
  $("results").innerHTML = '<p>Loading &hellip;</p>'; 
};


function loaded(data) { 

var res = data.query.results.item;
var html = "";
var i =  0;
var y = res.length;

for(i; i<y; i++) { 
    alert(data.deviceID);
} 

};

but this is the new error
Resource interpreted as Script but transferred with MIME type application/json.

  • 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-26T11:01:15+00:00Added an answer on May 26, 2026 at 11:01 am

    We are not allowed to do Cross-site HTTP requests from JavaScript. That is, you are only allowed to make AJAX requests to your own requestee domain only.

    You can only be successful with http://192.168.2.10:8080/commapi/comaction/init AJAX call if the AJAX call is made from the same domain as http://192.168.2.10:8080.

    As a workaround, this is often accomplished by JSONP which passes a JavaScript callback function which is a JavaScript function located on your page and requests to the server where the server wraps the JSON data with callback function. This is executed by creating a <script></script> tag with src attribute to be the AJAX url and appended to the HTML body.

    PS: You server must have capability to wrap your output data which will require to change on your http://192.168.2.10:8080/commapi/comaction/init codes.

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

Sidebar

Related Questions

I have this piece of code: this.json.each(function(obj, index) { var li = new Element('li');
I have this piece of code , geocoder = new GClientGeocoder(); var state; function
I have this piece of code: var myObj = function () { this.complex =
I have this piece of code in javascript: var catId = $.getURLParam(category); In my
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I have this piece of code: function func1(text) { var pattern = /([\s\S]*?)(\<\?(?:attrib |if
I have problem with this piece of code: var el = $('div#editor'); el.find('*[contentEditable]').removeAttr('contentEditable'); It
I have this piece of code: $(document).on(click, #breadNavMain, function() { for(var i = 0;
For instance, take this piece of code: var person = new Person(); or for
I have this piece of code: function CallAPI(paramString) { var returnVal; var jqxhr =

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.