getting JSON from PhoneGap application ? - ajax

i'm trying to send a getJson call from my app to get an external JSON from PHP file. all i'm getting is a gray empty screen ? can anyone tell me what's the problem or at least how can i debug to get the problem
here also attached the PHP file running !!

You need to provide more Information . Try to debug using Firebug , This is available for both chrome and firefox and since your using html run it in your browser and see what you get.
Do console.log(data); and see what is being outputted in your firebugs console tab. You might be running into some cross domain issue too. Use jquery ajax jquery JOSNP to over come this. just put data: jsonp .
Hope this helps you , please provide more information.

Related

Get the redirected URL of an Ajax call / Open an hidden InAppBrowser Sencha 2.2.1

I am working with a Sencha Touch 2.2.1 application. In my application, I am using Ajax call to perform an activity. The URL I specified in Ajax request will redirect to some other URL after execution. To complete my process I need to get that URL. I went through almost all questions regarding the topic in stackoverflow. Unfortunately nothing works. I tried getAllResponseHeaders() and some other answers I found in stackoverflow.
I tried to open that Ajax url: value in window.open() function in InAppBrowser. But It Opens a new window. I don't need it. So to solve this problem, that is to get the new URL, I think there are 2 ways.
Any mechanism to return(get) the redirected URL to the Ajax call
Any way to open a hidden InAppBrowser and execute the URL & get the result.
Second way is the best I think, But any helps regarding the topic is appreciated.
OMG !!
Finally I found out it.
To get the Redirected URL I give the URL to an InAppBrowser. My problem was how to open the browser window in hidden mode..!! The latest Cordova docs explains about it. I was referring the old docs. That's why I didn't get the answer. The Solution I found out is this: when open InAppBrowser open it in hidden mode..! That's all..!!
var ref = window.open(authorize_url, '_blank', 'location=no,hidden=yes');
This hidden=yes solved my problem.

angularjs looking for files on localhost after grunt-distribution

i'm working on a project with angular and grunt. before "grunting" angular reads the local files, but after "grunting" my index.html-file doesn't show anything. the tool "console" in chrome show me this error message:
"XMLHttpRequest cannot load file:///Users/userxx/Dropbox/Produktion/_resources/workspaces/userxx.html5/taleshipkiosk/_temp/repository/taleshipkiosk/dist/views/kiosk.html. Origin null is not allowed by Access-Control-Allow-Origin. index.html:1"
its seems that angular is still looking for one local file called "kiosk.html". but how can that be? this file (kiosk.html) is already in my dist-folder.
any ideas how to fix it?
thx
This doesn't look like it's really related to grunt at all. It seems like you're trying to make an XHR request that Chrome is regarding as cross-origin. You should try looking for answers regarding "origin null not allowed"
example: https://stackoverflow.com/a/4752452/628699

POST is not getting through to web service

I've added my code to pastebin at the following address:
http://pastebin.com/L03zGPhS
The service is up and running.
I can invoke it. I am additionally using firebug and getting the following results on the POST:
POST http://localhost:51204/AddrService.asmx/GetZipCode
15ms
HeadersPostResponse
JSON
zip
"40"
Source
{'zip': '40' }
Showing the service function:
[WebMethod]
public List<Zip> GetZipCode(string zip)
I can get this to work with jQuery 1.4.2, but I'm upgrading a lot of jQuery widgets to 1.8 and can't get the autocomplete to work. Am I missing something they changed in the AJAX autocomplete call. Documentation to a correct answer will suffice if it is useful.
UPDATE I found through Google Chrome that I'm getting a 500 error. I'm not certain why because I'm hitting localhost on both the service and the aspx page. Does anybody know if they changed something that would affect the security of hitting localhost, or if I could have possibly left out and important jQuery reference that would let autocomplete work for 1.4 but not 1.8?
Maybe this sheds light on your problem — the autocomplete API states that :
"You must always call the response callback even if you encounter an
error. This ensures that the widget always has the correct state."
(source : http://api.jqueryui.com/autocomplete/#option-source)

How to debug a failed ajax request in google chrome?

I have a web application that crashes on ajax requests with google chrome (it works with every other web browser it was tested it). After debugging I found that the error is caused by response.responseText being undefined. The xhr object looks like this:
argument: undefined
isAbort: false
isTimeout: undefined
status: 0
statusText: "communication failure"
tId: 3
In debugger in the 'network' tab I get "(failed)", however all the headers are there and I can even copy into clipboard the response body (which is a valid JSON).
My question is - how can I debug this problem? Where to find additional information, what causes this request to fail?
I finally found the solution to my problem : AdBlocks, when it blocks an ajax request, it just says "communication failure".
The first thing I would double-check is that the data coming back from the response is valid JSON. Just pass it through a JSON validator like this online JSONLint: http://jsonlint.com/
I assume that you are using something like jQuery to make your AJAX requests. If so, then make sure that you are using the development version of that library. Now that you are using the development version (uncompressed) of the script, find the particular function that you are using (eg. $.ajax) and then, within the Chrome inspector, insert a breakpoint in the code where the AJAX response is first handled (eg. https://github.com/jquery/jquery/blob/master/src/ajax.js#L579). Then proceed to step through the code, inspecting various return-values to see exactly what is going wrong.
If you are not using something like jQuery to make AJAX calls, then I'd recommend using a framework to avoid possible cross-browser compatibility issues like you might be experiencing right now.

display message on success return in ajax with jquery problem

i am using ajax with jquery .i have written this code:
$.ajax({url:"myurl.php",
data:datastr,
type:"POST",
success:function(data){
$("#msgbx").text(data);
}
});
it done what i want at the backend but doesn't show the return message in div with #msgbx id.
what is the problem?
The problem may be related to the formatting or encoding of your returned JSON object, or it may be a failure on the server that occurs after all your other processing is done, but immediately before you return your data.
Without seeing any other code, try looking at the console window in either Firebug or Chrome's web development tools to see what your server is responding with. You should see an Ajax POST method logged to the console window. Assuming you don't have an error code shown there, check to see what sort of data is being returned (or if any is being returned at all).
If you are getting data back from the server, your problem is in how you're displaying that on the page / inserting it into the DOM. If on the other hand you aren't returning anything, you'll need to check your PHP code to see where other problems might exist in your logic.
Feel free to add more to your post so we can give more specific answers.
use $("#msgbx").html(data);

Resources