i am trying to run my app after using phonegap but failing to pass the AJAX code section
it work perferctly on Ripple emulator but after installing it on my device (android 5.0) the ajax call just failed (Getting the ErrMSG).
Thanks
this is the code i am using:
$.ajax({
type: "POST",
url: "LogIn.aspx/UserCheck",
data: "{'UserName':'" + UserName + "','Password':'" + Password + "'}",
contentType: "application/json",
dataType: "json",
success: function (msg) {
if (msg.d == true) {
window.location.href = "Default.aspx";
}
else
alert("please insert correct username and password");
},
error: function (xhr, textStatus, errorThrown) {
alert('Ajax Call Failed');
}
});
It looks like your ajax call is calling on your local web server. Since you are not running now on your local web server you will need to adjust your ajax call to hit the full url. You have two places (at least in the code you have provided):
url: "LogIn.aspx/UserCheck"
and
window.location.href = "Default.aspx";
This last bit of code really needs to be a page or block of code in your app. This way if the phone is not connected to the Internet for whatever reason you still can give your users a valid error message.
Once this is done you will then need to whitelist your domain in your app.
After deploy to phone, you have a Cross Domain call to your aspx. so you also need to enable Cors.
Why do you redirect to default.aspx after login? if you redirect from the original index.html, which is located in the phone to the default.aspx which is located in the IIS Server, you lost control of the phone application, all plugins will not work, just like your apps become a mobile browser.
btw, r u using vb or c# in the aspx?
Related
I'd add a comment here:
PhoneGap application not working on Google Ripple
but given my low reputation on StackOverflow (as elsewhere), I can't. That thread raises similar issues but does not answer my question. I am trying to test the functionality of an HTML5 page that will eventually be made into a mobile app with PhoneGap. The page makes an AJAX call to a JSON service via jQuery:
$(document).ready(function() {
$.ajax({
url: 'latest.json',
type: 'get',
datatype: 'json',
processData: false,
success: function(data) {
//…make it so
});
});
and runs flawlessly as HTML5 in Chrome. However, when using the Ripple PhoneGap emulation available for Chrome, the JSON fails with a 500 error:
GET https://rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=latest.json 500 (Internal Server Error) rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=latest.json:1
The suggested answer to the question linked above reads:
I had the same issue. It was happening when I was trying to connect to my WebAPI service hosted on IISExpress.
After I changed hosting to my local IIS server, the error dissapeared (sic) and I was able to connect to my WebAPI service using Ripple.
But I'm not running IIS or indeed anything locally -- it's all running off a remote server hosted by an ISP. Since, as I say, this page runs fine in non-emulation mode, the fault would appear to be in Ripple. Any help making this emulation operate correctly will be greatly appreciated.
$.ajax({
type: "GET",
url: serviceurl + "/GetBusinessPartner/",
dataType: "json",
crossDomain: true,
success: function (responseData) {
},
error: function (xhr) {
}
});
This worked for me and in ripple setting disable cross domain proxy.
A am trying to make a fairly simple ajax call to my server to handle login etc. the app is written using sencha, with phonegap. As far as I am aware, because phonegap sends all requests as file// cross-domain issues do not apply. However I am constantly getting failures when testing this on a real device. If I implement the sencha app as localhost then everything works fine (this is making a call to a different server). The call is successful etc. However when I build it in eclipse and port it to my phone, I always get a failure. the code I am using is below, but I don't think it is this because as I say, this works locally.
Ext.Ajax.request({
url: 'http://xxx/global/external_api.ashx',
timeout: 3000,
method: 'POST',
params: requestData,
success: function (xhr) {
alert('Success: ');
},
failure: function (e) {
alert("An error occured connecting to the server: ");
}
});
Anyone have any other thoughts?
Seems to be something to do with the newest 3.2 build.. reverted to 2.9 and it works fine.
As the title says, I'm trying to access (POST) using jQuery AJAX call to a web url, http://host:port/... or http://localhost:8080/... from a local HTML file, c:\home.html. I can't get it to work.
I did Google and also saw several questions here but I can't get it to work. I need some help here. Here is what I've tried so far.
dataType: jsonp
crossDomain: true
Setting the header in my response:
response.setHeader("Access-Control-Allow-Origin", "*");
None of the three browsers are working - IE, FF or Chrome. The request is never reaching the server. Here are some of the errors I'm seeing.
No Transport (IE) if not jsonp is used.
NS_BINDING_ABORTED / Error loading content (NS_ERROR_DOCUMENT_NOT_CACHED) in FF
This is my code. I would appreciate any help. I'm using jquery-1.8.2.min.js.
var http_host = "http://localhost:8080";
function su (pc, p) {
var suUrl = http_host + "/ps/api/v2/authorize.json";
$.ajax({
type: 'POST',
url: suUrl,
data: {
phone_cell: pc,
password: p,
},
dataType: "json",
crossDomain: true,
success: osu,
error: oe
});
return false;
}
function osu (d) {
console.log(d);
}
function oe(xhr, ts, et) {
alert("ServerError: " + et);
}
An example would be a perfect pointer.
I suppose my code got messed up w/ all the different solutions that I was trying. I was finally able to get it to work w/ setting the header (solution that was recommended and worked for others). All that I had to do to get it to work is add the following to my REST service response.
response.setHeader("Access-Control-Allow-Origin", "*");
Update:
I thought I figured this out but I've not. There is more it than just setting the header. Anyways, in my specific situation. I was trying to run my app (html, js) off of the hard drive specifically on chrome and trying to access web services available on the cloud.
Here is how I finally solved the problem. I started the chrome w/ the following parameters.
--disable-web-security -–allow-file-access-from-files
Like I mentioned earlier, this app is really a desktop application that will be run as part of the chromium embedded framework.
Thanks every one for your input.
You can't make a cross-domain request from a local file because it's not on a domain. You need to host C:\home.html on a local webserver instance in order for it to work.
Ok, Here we go. I have already searched the Stack for the answer i have found some useful info but i want to clear up some more things. I also search the net for the answer but no real help.
I have worked with some api (yelp, ouside.in). In yelp i use to inject the script to head with the url request to the api with a callback funcion. I worked fine in all browsers. But while using outside.in api when i call the url the callback in not working.
In yelp they have a url field can be used like that callback=callbackfuncion so the callback will automatically called.
But in outside.in there is not such field available. Is there are any standard command for callback function which will work regardless of any server/api?
I also tried a standard ajax request using jQuery $.ajax() function. It worked for my local pc for both IE and other browser but did not working in IE showing the error: access denied, other borwser seems ok. Firebug in my FF also don't notice any errors.
Outside.in has an javascript example but it is too hard to me to understand
github.com/outsidein/api-examples/tree/master/javascript/browser/
site i am working: http://citystir.com
yelp: yelp.com
outside.in: outside.in
Techniqual info:
i am using: wampserver in local, wordpress for hosting, Godaddy, apache for remote with linux.
Codes:
Using Jquery $.ajax
url is like: "http://hyperlocal-api.outside.in/v1.1/states/Illinois/cities/chicago/stories?dev_key="+key+"&sig="+signeture+"&limit=3
function makeOutsideRequest(url){
$.ajax({
url: url, dataType: 'json', type: 'GET',
success: function (data, status, xhr) {
if (data == null) {
alert("An error occurred connecting to " + url +
". Please ensure that the server is running and configured to allow cross-origin requests.");
}else{
printHomeNews(data);
}
},
error: function (xhr, status, error) {
alert("An error occurred - check the server log for a stack trace.");
}
});
}
Thanks!
This question was asked in the Outside.in developer forums this morning as well (presumably by the same person). Here's a link to that discussion: http://developers.outside.in/forum/read/97053
To summarize, the Outside.in API does not support JSONP, but CORS support is included in the next release of the API, which will hit in the near future.
I have the following script in my web page to call out to a JSON-enabled WCF service that I have created and am hosting on my web server. However, the alert displays "null". When I point to the url in a browser it returns very simple JSON: {"city":"Ann Arbor"}. Also, when I run the page containing the code below with Fiddler running, I can see the service is hit and the JSON returns. But still the success function below returns null. Anyone know what I'm doing wrong? Thanks. -Ned
<script type="text/javascript">
$.ajax({
type: "GET",
url: "http://192.168.192.17:8080/Service.svc/class/",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert(data);
}
});
</script>
I suspect the problem comes from the fact that you are trying to call a web service using AJAX which is not hosted on the same domain as the calling script and thus you are violating the same origin policy. If you want to be able to call http://192.168.192.17:8080/Service.svc using AJAX, the calling script needs to be hosted also on http://192.168.192.17:8080.
As a possible workaround you could use a server side script acting as bridge hosted on the same domain as the client script or use JSONP if you have control over the web service.
You could define an error function to see what the problem is:
$.ajax({
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown)
},
//.......
})