I am currently trying to develop a phone app using PhoneGap. It's a game item app that should retrieve information from a database I have compiled. I have a .Net project that exposes the data using .ashx file.
The problem is that I cannot retrieve the information from the site with getJSON...
I have the following very simple C# code that generates the information server-side:
public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString["id"] != null)
{
using (DataClassDataContext db = new DataClassDataContext())
{
Item item = db.Items.FirstOrDefault(x => x.ID == Convert.ToInt32(context.Request.QueryString["id"]));
string json = "{";
json += "\"NameEN\" : \"" + item.NameEN + "\",";
json += "\"DescriptionEN\" : \"" + item.DescriptionEN + "\",";
json += "\"ID\" : " + item.ID.ToString() + "";
json += "}";
context.Response.Write(json);
}
}
}
This is working very well and when I go to /JSONhandler.ashx?id=xxx I get valid JSON and everything is fine.
The problem is that when I try to access the information with my script it all goes downhill...
I use the following to access the information:
$(document).ready(function () {
var url = 'http://mydomain.com/jasonhandler.ashx?id=';
var query;
$('button').click(function () {
query = $("#query").val();
$.getJSON(url + query, function (json) {
$("#results").append(json.NameEN + ' ' + json.DescriptionEN);
});
});
});
When I use chrome I can see that the status of the call is cancelled and nothing is returned. When I run the same script locally there are no problems.
I have also tried the following:
$(document).ready(function () {
var url = 'http://mydomain.com/jsonhandler.ashx?id=';
var query;
$('button').click(function () {
query = $("#query").val();
$.ajax({
type: "GET",
url: url + query,
async: false,
beforeSend: function (x) {
if (x && x.overrideMimeType) {
x.overrideMimeType("application/j-son;charset=UTF-8");
}
},
dataType: "json",
success: function (data) {
$("#results").append(data.NameEN + ' ' + data.DescriptionEN);
}
});
});
});
and the result is almost the same. The status of the call is pending instead of cancelled. But the endresult is the same... I get nothing.
Can anyone give me any pointers as to what is wrong? I believe this is a cross domain problem but I am puzzled by the fact that I can access the information from twitter when I can't access the information from my own server...