Sencha Ajax call not working - ajax

I’m trying to access a web service with Sencha touch. With an JSONP call from the browser, all works fine. When we switch the application to a physical device, and change the JSONP request (no longer needed on an real device) to an ordinary AJAX call, nothing happens.....
What is the right way, to fix this? We're using PHONEGAP, I think something probably is wrong with the container, because the call itself looks like it should (-> And is working in the browser, where PHONEGAP is not needed and therefore not included.)
Here is my code:
Ajax-Call for the Mobile (not working)
// 1. When we use this on the DEVICE, it DOESEN'T work.
// It seems, like the call isnt fired at all
// JSONP we don't need here......
alert("Ajax request is send");
Ext.Ajax.request ({
url: Adress_To_Webserver,
method: 'GET',
timeout: 1000,
success: function(response, opts) {
alert("sucess");
//alert(Ext.decode(response.responseText));
//var obj = Ext.decode(response.responseText);
console.dir(obj);
},
failure: function(response, opts) {
alert("error");
}
});
JSONP-Call for the Browser (working)
// 2. If we do the same Call (JSONP) on the BROWSER, it WORKS.
alert("Ajax request is send");
Ext.data.JsonP.request ({
url: Adress_To_Webserver,
timeout: 1000,
callbackKey: "myjson",
params: {
callback: function (jsonData) {
}},
success: function(response, opts) {
alert("sucess");
alert(Ext.decode(response.responseText));
var obj = Ext.decode(response.responseText);
console.dir(obj);
},
failure: function(response, opts) {
alert("error");
}
});
It would be great, if someone have a hint/solution for this problem - like i mentioned, i'm using sencha architect to build a android app. The Phonegap folder with the .apk is created automaticaly, all permissions in the config.xml are set. Phonegap plugins have been also installed. Probably, some more dependencies are missing or wrong - what will be a good place for looking?
Thanks in advance for helping,
Daniel

It seems to me that you don't set up the <access> property in the config.xml file to origin="*" or whatever domain you need. This property specifies all exteranal domains which phonegap allows your web app to access.
So, your config.xml file should contain the following line:
<access origin="*" />
Instead of '*' your can put your resource from which you retrieve you data.
There is the explicit description how to use it white list (phonegap)

Related

Ajax call in Openshift throws 404 error

I'm trying to make a simple Ajax call in my app on Openshift. This is my ajax call which is triggered by pressing a button:
$.ajax({
url: 'http://my-site-name.rhcloud.com/asciimo',
method: 'POST',
data: {attr:"value"}
});
And this is node in my server.js file:
self.createRoutes = function() {
self.routes['/asciimo'] = function(req, res) {
res.send('done');
};
};
Everything works when I go to my-site-name.rhcloud.com/asciimo, but if I click a button (to get there) I get:
POST http://my-site-name.rhcloud.com/asciimo 404 (Not Found)
even though the link clearly works on it's own.
Change your method to GET
method: 'GET',
When you go to the URL directly in your browser, you are issuing a GET request, not a POST.
I know what the problem was now. In ajax there is a POST request and self.routes['/asciimo'] (given as a template by Openshift) deals with GET requests only. What solved the problem was simply rewriting my function as a separate POST function:
self.addpost = function() {
self.app.post('/asciimo', function(req, res){
res.send('done');
});
};

Plivo SDK call Recording

I am getting an error that i dont understand an cannot find any helpfull informations about:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https:*******' is therefore not allowed access. The response had HTTP status code 401.
function RecordTheCall()
{
var key = '*******************';
$.get( "https://api.plivo.com/v1/Account/"+key+"/Call/?status=live", function( data ) {
var callUuid = data.call_uuid
});
$.ajax({
url: "https://api.plivo.com/v1/Account/"+key+"/Call/"+callUuid+"/Record/",
type: "POST",
data: { 'auth_id': auth_id, 'call_uuid': CallUUID },
dataType: "json",
success: function (res) {
alert(res);
},
error: function(err) {
alert(err);
}
});
}
Call recording cannot be accomplished from the Web SDK directly. You cannot use the Plivo API from your Web browser using Javascript because cross-domain ajax requests are not allowed in browsers for security reasons.
This has been explained in this Wikipedia article. There are some work arounds to overcome this, but it is browser dependent and hence it might not work always. Instead you should use the Plivo XML/API in you application.

issue with Ajax dispatcher in typo3

I'm trying to grab some data from the database on a page in typo3 using Ajax . So after a long time looking for the appropriate way to do it , I got convinced that The Ajax Dispatcher is the best tool to do the job . So I created the file following the instructions to be found here.
Now when I make an Ajax call on my page , the console displays a 500 (Internal Server Error).
joined is a snapshot of my console tab.
and this is the jquery function that gets run on an onchange event .
function getContent(id)
{
console.log("Start process ...");
$.ajax({
async: 'true',
url: 'index.php',
type: 'POST',
data: {
eID: "ajaxDispatcher",
request: {
pluginName: 'listapp',
controller: 'Pays',
action: 'getMyCos',
arguments: {
'id': id,
}
}
},
dataType: "json",
success: function(result) {
console.log(result);
},
error: function(error) {
console.log(error);
}
});
}
Could someone please help me , I just started developing with this CMS of shit :p
If you indeed followed the tutorial step by step, and you use TYPO3 V6.2, you would get errors cause of depricated function calls to t3lib_div (as the title of the blog item says, it is for version 4.x)
Always keep your error.log open, it's your best friend in times of coding stress
You can also use typenum for ajax calls
http://lbrmedia.net/codebase/Eintrag/extbase-60-ajax-bootstrap/
I can imagine that starting with TYPO3 can be frustrating, but calling it a 'CMS of shit' does not seems to be a smart strategic move if you need help from people who think differently about it.

PhoneGap app for Symbian | "Application closed : WidgetUi KERN-EXEC 3"

I develop phonegap app for symbian (cordova for symbian I'm get from here)
After 3-5 seconds when my app begin execute ajax request, I get error:
Maybe someone faced with this issue?
Update1:
I make cross-domain ajax request with jquery mobile 1.8.1
$.ajax({
type: 'GET',
url: "http://example.org/some/path",
dataType: "json",
mimeType: "application/json",
headers: { "TOKEN": "%SOME_TOKEN%" }
}).done(function (data) {
// success processing
}).fail(function (xhr, textStatus) {
// fail processing
});
It could be as simple as the fact that you're missing " from the url line of your AJAX creation, but I suspect it isn't. I'm guessing that's a copying typo. This error message means your getting an uncaught exception which is bringing your app down.
Other people have reported JQuery for mobile being buggy, and having problems with certain HTTP Response statuses. I suggest bypassing it altogether, and making your own AJAX request, as a workaround (plenty of examples on the internet; I would alert the response status just so you can see what you're getting).. If that works, you can investigate whether other version of JQuery suffer from the same bugs.
Example AJAX without JQuery:
<script type="text/javascript">
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4)
{
// do stuff with xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
</script>
KERN-EXEC 3 is due to referencing a bad pointer or running out of stack space. It's probably the latter but it's impossible to say. Is there any way you can provide a call-stack?

Ajax request error when changepage

guys. I have a juerymobile multi-page, and I have a button in #page-index, when click it, will send a ajax request to server, and changepage to #page-column, It run will in PC, but when i deploy the multi-page in phonegap, the button click can just run only twice, code is below:
function test()
{
$.mobile.changePage('#page_column');
$.ajax({
url: "http://192.168.168.120:8090/fcmobile/getTest",
dataType: "json"
}).done(function(data) {
alert(data.content);
});
}
I found if I remove $.mobile.changePage('#page_column');, the ajax request can be run well any times. but when I add the changePage code, it only can be run twice, in third time, ajax request can't even be send. Dose anybody know reason?
AJAX is made to be asynchronous, so no need to set async to false to get it working. Use events instead.
For example:
function test () {
$.ajax({
'url': "http://192.168.168.120:8090/fcmobile/getTest",
'dataType': 'json',
'success': function (json_data) {
$(document).trigger('test_json_data_loaded');
console.log(data);
}
});
}
$(document).on('test_json_data_loaded', function () {
$.mobile.changePage('#page_column');
});
When you set async to false, you're basically making it so that every time this AJAX request is made, the user will have to wait until all the data is fully loaded before the application/website can do/execute anything else...not good.

Resources