local app with remote $.ajax request

14 views
Skip to first unread message

Julian Avram

unread,
Mar 7, 2009, 5:01:20 PM3/7/09
to phonegap
If I open index.html from the www folder in safari, everything works
properly. If I open it in the simulator or the device, things fail.
The jquery library is loaded:
<script type="application/x-javascript" src="js/jquery.min.js"></
script>
<script type="application/x-javascript" src="js/jquery-ui.min.js"></
script>

and works properly because I'm running jquery tabs on the same page.
Here is the json request: $.ajax(
{
type: "POST",
url: "http://MYURL/get_json.php",
dataType: "json",
data: "var=" + myVar,
success: function(msg)
{
var_dump(msg);

}

});

Julian




José Carlos

unread,
Mar 7, 2009, 5:42:46 PM3/7/09
to phon...@googlegroups.com
Have you tried with the $.getJSON?
This way I shouldn't have any problems, you just need to add ?callback=? at the end of the url and it should work fine.
--
José Carlos
-----------------
http://logon.com.pt

Julian Avram

unread,
Mar 7, 2009, 6:26:17 PM3/7/09
to phonegap
Thanks that worked. I'm making a $.getJSON request to:
http://myur.com/getjson.php?callback=&var1=test

Any ideea why $.ajax doesn't work?

Julian

On Mar 7, 5:42 pm, José Carlos <j.joaq...@gmail.com> wrote:
> Have you tried with the $.getJSON?This way I shouldn't have any problems,

José Carlos

unread,
Mar 7, 2009, 9:19:20 PM3/7/09
to phon...@googlegroups.com
I think it's to avoid cross-site scripting. Although you specify the type of return in the $.ajax, it throws an error if you do it to a external site. In order to avoid that they created the getJSON method.

Nunzio Fiore

unread,
Mar 8, 2009, 4:03:43 AM3/8/09
to phon...@googlegroups.com
Another useful and elegant way to do it is jsonp. I use it a lot in
mootools, probably jquery can do this too.
By
nunzio fiore
code is nothing without fantasy http://www.moonkiki.com
Reply all
Reply to author
Forward
0 new messages