An issue in cordova android related to cross-domain restrictions

My small cordova app utilizes beacon plugins to send a get request to a specific page once beacons are discovered. However, I have been facing issues with sending the get request to my server using the code snippet below with jsonp. Despite trying out different options, none of them seem to work.

$.ajax({
                    type: "GET", 
                    async: false,
                    dataType: 'jsonp', 
                    jsonp: 'callback', 
                    jsonpCallback: 'callbackFunction', 
                    url: "http://xxx",
                    crossDomain: true,
                    success: function(json){
                        alert("success");

                    },
                    error: function(){
                        alert("fail");
                    }
                });

Answer №1

For a recent project of mine, I implemented a similar solution. Take a look at $.getJSON for more detailed information.

$.getJSON("http://example.com/project/login.php?callback=JSON_CALLBACK&e=" + email + "&p=" + password, function() {
 console.log( "Call successful" );
})
.done(function(data) {
    console.log(data.status);
 })
.fail(function() {
    console.log("There was an issue with the AJAX request in login.php.");
});

When responding in PHP, make sure to include $_GET['callback'] and follow the JSON format if you're sending data back:

echo $_GET['callback'] . '(' . "{'status' : 'success'}" . ')';

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Environment Variables during the build process in a VueJS project

During the build stage of a CI job for my VueJS app, I am attempting to utilize an environment variable provided by GitLab CI called CI_COMMIT_SHORT_SHA. build: image: node:latest stage: build variables: CI_COMMIT_SHORT_SHA: "$CI_COMMIT_SHORT_S ...

What is the method for determining the active configuration?

I am working with a MongoDB database that consists of 3 collections. Each collection is exemplified below by a document: tag _id: ObjectId('61b873ec6d075801f7a97e18') name: 'TestTag' category: 'A' computer _id: ObjectId(&apo ...

What is the best way to send two Array objects through http requests in AngularJS?

Is there a way to receive two parameters as an array in an HTTP action, like List `abc` and List `xyz`, and then use a model class? public class ItemAndChecque { public List<SaleItem> saleitem { get; set; } public List<itemChecqe> item ...

Access the value of a field inside nested objects (Parent-child) by using underscore.js

const paths = [ { path: 'RS', hasChild :true }, { path: 'MO', hasChild: true }, { path: 'EL', hasChild: true }, { path: 'CL', ...

Tips on Eliminating Square Brackets from JSON Using PHP or JavaScript

Query : Is there a way to easily convert the JSON format shown below? Original Format : [ {"u0":{"user_id":"124", "name":"Eloise R. Morton"}}, {"u1":{"user_id":"126", "name":"Mary S. Williams"}} ] Desired Format : { "u0":{"user_id":"124", "name":"Elo ...

Transferring data from AJAX to PHP

I am currently developing a project in PHP. I have created an associative array that functions as a dictionary. Additionally, I have a string containing text with placeholders for keys from the array. My goal is to generate a new String where these key wor ...

Start the input field with the prefix "APP" and restrict the input to only numbers

My challenge involves creating an input field that requires a prefix of "APP " followed by 7 numeric digits. I initially considered using ngx-mask, but it appears to be impossible. Another approach I thought of was utilizing the (focusin) event like this: ...

Exploring object properties within arrays and nested objects using ReactJS

Within the react component PokemonInfo, I am looking to extract the stats.base_stat value from the JSON obtained from https://pokeapi.co/api/v2/pokemon/1/. The issue lies in the fact that base_stat is nested inside an array called stats. My assumption is t ...

Retrieve, process HTML table information using Ajax from an external server or website domain

In order to demonstrate: :the html table data source = "example.com/html_page_source" (tableid="source") :an xml file created from the specified table data = "pretendco.com/xml_built_from_html_table I am seeking guidance on how to build an xml file from ...

Simultaneous beforeSave actions permitting repetitions

To prevent certain objects from being created, I incorporated a conditional in the beforeSave cloud function of that object type. However, when two objects are created at the same time, the conditional fails to work as expected. Check out my code snippet ...

Tips on modifying the message "Please fill out this field" in the JQuery validation plugin

Is there a way to customize the message "This field is required" in the Jquery form validation plugin to display as "このフィールドは必須です"? Changing the color of the message can be achieved using the code snippet below: <style type="tex ...

Can anyone figure out why this code is not functioning properly? It seems to be targeting the body element and all of

Currently, I am utilizing jqtouch to create a mobile website. In addition to this, I am incorporating a gallery image slider into the website. However, I have encountered an issue where the images do not display when placed between <div id="project_name ...

most effective approach for recurring AJAX requests

Currently working on a web app that includes real-time features such as chat and auto-updating lists. Looking for the best method to perform interval updates using AJAX. My current approach is quite simple: updateAll(); function updateAll(){ $.ajax({ ...

How can I save the content from a tiptap editor in a PHP form?

I'm looking to integrate the TipTap editor into a PHP form as a textarea field. I've set up a Vue component and passed it to the blade view. Blade view: <form method="post" action="{{ route('dashboard.edit.postInfo', ...

Expanding application size by incorporating third-party libraries in NPM and JavaScript

My friend and I are collaborating on a project. When it comes to programming, he definitely has more experience than I do, considering I've only been coding for a little over a year. I've noticed that he prefers building components and function ...

The scope of JavaScript's dynamic object

Can created objects be utilized in a different scope? var iZ = 0; var pcs = {}; function Pc(_name, _os) //Constructor { this.name = _name; // Pc Name this.os = _os; //Pc Os this.ausgabe = function() { //Do something }; ...

Utilizing i18n's useTranslation and Redux's connect Higher Order Components to export components efficiently

My application has been utilizing Redux for quite some time, with the component exports structured like this: export default connect(mapStateToProps, mapDispatchToProps)(MyComponent); Now, I am integrating an i18n translation library and would like to use ...

Is there a way to use setTimeout in JavaScript to temporarily stop a map or loop over an array?

data.forEach((d, i) => { setTimeout(() => { drawCanvas(canvasRef, d); }, 1000 * i); }); I have implemented a loop on an array using forEach with a one-second delay. Now I am looking to incorporate a pause and resume f ...

Troubleshooting ngFor in Angular 5

I'm currently working on a component that needs to display data fetched from the server. export class CommerceComponent implements OnInit { dealList; ngOnInit() { this.getDeals(); } getDeals(){ this.gatewayService.se ...

Using a UUID as the default ID in a Postgres database system is a straightforward process

As I transition to postgres from mongodb due to the recent announcement, I've noticed that the IDs are simply numerical and auto-incremented. I've attempted a few solutions: Setting the default ID to a UUID with a lifecycle hook - Unfortunately, ...