Acces to other domain not working

  • 1
  • Question
  • Updated 4 years ago
I work on simple app. I create only a html file and js files and css. I try to load an ajax data from other server. Everything works coreectly on debug on but when i debloy key on adobe phonegap site and try app then app when i call ajax json get then i have readystats 0 and status 0. I use adobe phone gap build.

and js function

------
function log_in() {

window.login_data = $("#login_form").serializeArray();
window.username = login_data[0].value.toUpperCase();
window.password = login_data[1].value;
if (window.password == "" && window.username == "") {
window.username = "a";
window.password = "a";
}

var serwer_url = window.serwer;
var index = serwer_url.indexOf("/");
index = index + 1;
window.header = serwer_url.substr(0, index);
window.rest_url = serwer_url.substr(index + 1);
$.ajax({
type: 'GET',
async: true,
crossOrigin: true,
url: window.header + window.username + ":" + window.password + "@" + window.rest_url + "/rin/mob_leady?resultsPerPage=100",
data: {},

beforeSend: load_start(),
success: function (data) {
window.test = data;
console.log("autoryzowano");
$("#login_error").css("display", "none");
$("#leeds-content").load('auth_app.html');
$("#leeds-content").css("display", "block");
$("#login").css('display', "none");
$("#contact_info_load").remove();
},
error: function (xhr,err) {
console.log("nie autoryzowano");

$("#login_error").append("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
$("#login_error").append("responseText: "+xhr.responseText);
$("#login_error").css("display", "block");
$("#password").val('');
$("#username").val('');
$("#contact_info_load").remove();
}
});
}---------
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
How did you whitelist the external domain?
Did you wait for the deviceready event to fire before attempting to make the ajax request?
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Did you wait for the deviceready event to fire before attempting to make the ajax request?
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
I have document ready only because i have only a index.html with css styles and js files with script i paste above.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
document.ready means that the DOM is loaded.
Did you include a reference to cordova.js? If not, please do so. Then add an eventListener for 'deviceready' and in the callback function, perform your script.
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
you meant add to the meta cordova.js file (i dont have it ) and after thata repelace document ready to device ready and inside that put ajax function ?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
No.
You should add
<script src="cordova.js" />
and add an eventListener for 'deviceready'.
In its callback function, you can make the ajax request.
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
Right now i have something like that :

Is that possible to ssl certyficate block phone gap get request and returns status 0 readystatus 0 ?
I try to :
1. Change servet to https on diffrent port and its work fine
2. Find example link to json via http from network and itsh work fine
3. Find example link to json via https from network and itsh work fine
4. App work correctly on debug mode when i buidl id on adobhe phone gap and add key than the error shows
5. App work correctly on browsers but after buidl in phone gap fails

I use Cli 5.2 and phone gap build
Photo of JesseMonroy650 (Volunteer)

JesseMonroy650 (Volunteer), Champion

  • 3325 Posts
  • 122 Reply Likes
@Przemysław
It is apparent you don't yet know enough about Phonegap. Please read this FAQ: Top Mistakes by Developers new to Cordova/Phonegap.

Please read the bold sentences and return with your questions.

Jesse
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
Ok, Thank you :)
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
Ok i read this.
I add devic ready i set all plugins to the same source dont use cli version on phone gap build but still have the same error. I read this bold sentences "When designing the app, thinks phonegap works like a website or webbrowser" but i dont have any idea what i can do now with this to start this work correctly
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
If your zip file is available online somewhere, please post its url and I'll be happy to have a look.

When you do, please also post where (in which html document) the ajax function is performed, so I won't have to work my way all through the entire app looking for it.
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
Wait a sec i will paste a link
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
OK. Here is some feedback:

1. You have included a cordova.js file. Can't do that. PGB will include one automatically.
Remove the file (but keep the reference!)

2. You specified the old names of the plugins at the pgb repo. Be aware that the plugins at npm are named differently. For instance: cordova-plugin-camera
BTW: Do you really need all those plugins?

At the bottom, you do have a collection with the proper plugin names. So now, you have several plugins twice.
That's a bit of a mess....you should clean that up.

3. You have set orientation to default, which is both landscape and portrait. However, you only have splashes for portrait (except one). Also, you don't have all recommended and required dimensions.
You need to complete that, or set portrait only (and complete anyway)
Furthermore, why did you include any blackberry splashscreen?

The splashes are not included in your zip. You don't even have the mentioned directories. Why not?

Icons are missing, too (except a default one, but that won't do for iOS. Your app will fail verification when publishing)!

4. You have
<access subdomains="true" origin="*"/>
twice. Would that be any better than just once?

5. In your index.html, the markup doesn't validate. You have
<style>
</style>

outside HEAD and BODY, which is incorrect

6. In your index, in the form element, you have:
action="javascript:log_in(); display: block;"
What is this display: block doing there? That's not javascript.

Since you are using jQuery, you should use the .submit() method of $("#login_form") to handle the submission. Not an action attribute.

============

Perhaps correction of the above points makes your ajax communication work. Perhaps not yet, but it is hard to debug with so many different errors present in your code. So, I would suggest you work on this first, then we can continue.
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
I forgot to add i send this file and build via build.phonegap.com
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
I clearup thiss mess
Here link
http://www.filedropper.com/project_2
I don't get what you mean with this :
"Also, you don't have all recommended and required dimensions. "
Can you look on this what i upload ?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
So, now you have neither splashes nor icons. These are, however, highly recommended for Android and required for iOS.

Your default icon should be 'icon.png', according to the Icons and Splashscreens section of the PGB Docs.

You should check if your script login.js throws any errors while loading. After all, it contains jQuery-style language, as in $.ajax({..., which is syntactically incorrect as long as you haven't loaded jQuery. And you haven't!

I wonder if your server "https://system.fastdata.com.pl:4567/a......" blocks requests from apps server-side. You should check at the server if that is the case.
In any way: these extras should not be necessary:
- crossDomain: true,
- $.support.cors = true;
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
I loaded Jquery from file jquery-2.2.0.js in index.html

Is that wrong ?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You load it AFTER the login script. I would have expected it to be loaded first.
But my main point would be the server, blocking a request from the device somehow (because you wrote that the other urls were loaded correctly).
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
But i saw a server logs and ther is any sign of connect try.
Samething new is that i get the server on other port and change http to https and its work correctly.
I dont have any idea what is wron
Everything work perfectly when i build it on Phone gap build. When i dont choos from select menu key for that apllication :/
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
So, it appears not to be a PGB problem, then?
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
Maybe ssl protocol ? Is something for phongap wchich accept mayby defined ssl protocol by fingerprint or something like that ?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
No.
Besides, you said the other urls are requested correctly. One of them was https://, too.

You may want to try and whitelist "https://system.fastdata.com.pl:4567/*" in your config.
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
The server right now after those changes response but rejecting ajax get call because like my temate say server dont get url wchich i asking. Probably he get him wrapped or this is encryption problem.Is it possible ?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
The server right now after those changes response but rejecting ajax get call because like my temate say server dont get url wchich i asking.
I might be misunderstanding this phrase.
Are you saying:
- the server responses (how?)
- the server rejects an ajax get call (how does the server know this is done using ajax?)
- the server doesn't get the url you are asking for (how are you asking for an url, and why should the server not 'get' it?)

Probably he get him wrapped
I have no idea what this means. Who is 'he' and who is 'him'? What is supposedly "wrapped" and with what is it wrapped?
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
Sorry for post above here is explanation.
Right now we have connect to server. Befor apply those tips you give me petra(Thank you very much) we dont have any sign of connect to server.
Right now we have but unforunelly the connection always end very fast so we think it is a certyfication error because the site in browser on adroid devices have a red lock(that means the site is unsafe ). Is it possible in this case to android abort connection ? And why on 3 diffrent smartphones, on two devices page have a red lock but one have green ?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
And why on 3 diffrent smartphones, on two devices page have a red lock but one have green ?
Most likely, the green browser has once accepted the certificate. The others haven't (yet).

I suppose the disconnection from the app is a server configuration issue. Sorry, but I wouldn't know how to help you with that.
Photo of Przemysław Zamorski

Przemysław Zamorski

  • 18 Posts
  • 0 Reply Likes
Thanks petra. You help my very much in this topic and thanks for patience ;) have a nice day