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

  • Home
  • SEARCH
  • 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 9275159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:31:18+00:00 2026-06-18T16:31:18+00:00

Hi I have to write Rest API call which will serve cross domain request

  • 0

Hi I have to write Rest API call which will serve cross domain request

I have checked with Mozilla (rest client) with request and it serves me data now how to write via jquery/javascript in html.

{"POST to adengine":{"method":"POST","url":"http://xxx.com/Advertisement/1.0/GetAds","body":"aid=Apposaurus_xxx","overrideMimeType":false,"headers":[["Content-Type","application/x-www-form-urlencoded"]]}}

Here is my sample code in html

<html>
<title></title>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">

JSONTest = function() {
    var resultDiv = $("#resultDivContainer");
    $.ajax({
        url: "http://xxx.com/Advertisement/1.0/GetAds",
        type: "POST",
        data:  "aid=Apposaurus_xxx",        
        overrideMimeType:'false',
        crossDomain: 'true',
        dataType: 'jsonp',
        headers:{"Content-Type":'application/x-www-form-urlencoded'},

        success: function (result) {
            switch (result) {
                case true:
                     processResponse(result);
                    break;
                default:
                    resultDiv.html(result);
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        }    
});
};
</script>
</head>
<body>


<div id="resultDivContainer"></div>

<button type="button" onclick="JSONTest();">JSON</button>

</body>
</html> 

Where i am wrong?

  • 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-18T16:31:20+00:00Added an answer on June 18, 2026 at 4:31 pm

    Cross Domain Request should be accomplished using JSONP. JSONP stands for JSON with Padding. I’ll try to explain it here a little.

    How do you want to fetch data (script when we talk about JSON) from server? You have two ways:

    1. An ajax request, which is done behind the scene using an instance of XMLHttpRequest object, and which is limited to be sent only to the same domain,
    2. A simple HTTP Get request, which is done via inserting a <script> tag somewhere in the HTML document, mostly in the head section.

    The second technique is not limited to Cross-Domain Policy. However, let’s examine how browser works as our agent in these two scenarios:

    ajax scenario: developer code => browser => request => server => response => browser => developer code. This means that when you use ajax, browser on behalf of you creates an HTTP Request (with X-Requested-With: XMLHttpRequest header field) and sends it to the server, then it gets the response base, *but it gives you the response back, so that as the developer, you have the opportunity to analyse response and do whatever you want to do with it.

    HTTP Get scenario: developer code => script tag in head => browser => request => server => response => browser => response execution.

    See? When you use JSONP, or when you insert in simple <script> tag in head, browser gets the script back from the server, but it runs script and that’s the end. You haven’t been hooked into the response, and you don’t have control over it. Thus, you need to provide a callback function for it. callback({}) differs from {} in point that when it gets executed, it gives you the opportunity to get the result and do something with it.

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

Sidebar

Related Questions

I have a rest service returning some data. I use Restlet client api as
I need make a GET call to a REST api which is rate limited.
I have write my own view Bar, which extends LinearLayout . My bar has
I'm working on an application so i have write an dll which contain a
I have to write a SNMP module which monitor a certain server application that
I have to write 3 functions which accepts a parameter of BaseClass type and
I have a REST API written in Java running under JBoss. Recently we updated
I have a REST API written in PHP located on Apache server. It takes
I have a Javascript API, which should be usable with GWT and Flex. Using
Our server web app will handle jobs that are requested by REST API requests.

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.