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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:47:46+00:00 2026-06-17T20:47:46+00:00

I need to implement a cross-domain POST request. Using this code, everything worked fine

  • 0

I need to implement a cross-domain POST request.
Using this code, everything worked fine in the same domain. But when I moved the backend to another domain – all stopped working! Therefore, there can be typos. There can be only where the error is related to the cross-domain request.
I try send POST request using ajax and JSONP:

function requestToServer(url, success, myObjects) 
{
    $.ajax({
        type: "POST",
        crossDomain: true,
        dataType: 'jsonp',
        jsonp: 'jsonp_callback',
        url: url,
        data: "arrObjects=" + JSON.stringify(myObjects),
        success: function(data)
        {
            success(data);
        },
        error: function()
        {
            alert('Server connection error!!!');
        }
    });
}

and server-script, where send data:

<?php

header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');

include 'connection.php';

$arrObjects = json_decode($_POST['arrObjects']);


$title = $arrObjects->title;
$msg = $arrObjects->msg;
$lat = $arrObjects->lat;
$lon = $arrObjects->lon;

$query = "INSERT INTO `geo_markers` (`id`, `title`, `description`, `lat`, `lon`) 
VALUES (NULL, '{$title}', '{$msg}', '{$lat}', '{$lon}')";

$res = mysqlQuery($query);

echo $_GET['jsonp_callback'].'({"success":true});';

mysql_close();
?>

but $_POST is empty. But $_GET takes values $_POST. If I check $_POST using var_dump, it is array(0), $_GET contains all send data!

What’s wrong here? What went wrong can it be?

  • 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-17T20:47:47+00:00Added an answer on June 17, 2026 at 8:47 pm

    You have send JSON formatted since you are using jsonp format. try json_encode before you echo data.

    Also keep in mind that when you make a cross domain jsonp call, JSONP isn’t AJAX, it’s merely a dynamic script element. You can’t do a POST with a dynamic script element. There’s no place to put the POST data. So You will have to use GET method.

    Also keep in mind that you can use below format

    $.getJSON(url + "?callback=?", null, function(data) {
    
    });
    

    Read more

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

Sidebar

Related Questions

I need to implement portable code, but I do not know how to deal
I need to implement authentication in a php app but using fingerprint as part
We have a large number of websites which need to implement cross domain login,
I am trying to make a cross domain HTTP request to WCF service (that
I am trying to POST to my cross domain * Rest service * via
I need to implement cross platform handler for the removable media mount/umount events. It
Some time in the near future I will need to implement a cross-language word
we have this application which uses cross app domain (2 app domains in the
this code: $(document).ready(function() { $('body').click(function(evt) { if(evt.target.nodeName === 'A' && $(evt.target).hasClass('cross-link')) { $('a[href=#2]').trigger('click'); }
I'm current working on some stuff that need to send cross-domain ajax requests. I'm

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.