My setup is like so:

An SQLite database sits in one of my Apache folders

A Perl cgi script sits in the same folder, with public permissions, so that it can handle database interactions

A C program, running on the same machine, listens on a specific port for specific JSON requests and responds with specifically-formatted JSON data

A webpage, written primarily in jQuery and HTML, must access both the SQLite database and the C program somewhat constantly. It does so using AJAX requests -- here's an example from the code:

function sendCommand(cmd, callback) {

$.ajax({url: "http://192.168.42.90:6112/?cmd=" + cmd,

dataType: "jsonp",

success: function(d,s,x) {

callback(d);

},

jsonpCallback: "json",

error: function(xhr) {

alert('Error: ' + xhr.status);

}

});

}

So I might invoke it with something like sendCommand("get_x", updatePosition) -- so that it'd send the get_x command along to the C program, and, if it got good feedback, run said feedback through the updatePosition function.

So all of this works SPLENDIDLY if I'm running on a webpage on the same machine. If I move to another machine -- in this case, specifically, an Android phone, doing tethered IP over USB, it ... sort of works. This is what's puzzling me -- it doesn't silently fail, like I'm used to JavaScript doing. Instead, as far as I can tell, it sends the request out, claims that it got data back, and runs the callback function -- only, according to the C program, nothing ever happened; according to Wireshark, no packets were sent; and the "data" that it gets back is an empty, specially-formatted string. If I'm expecting "(5,5)" as output from C, it's getting "(0,0)" -- why is it getting anything at all? Much less filling "(,)" with 0s?

Very strange. I've tried various little things, like changing the dataType to "json", making sure all my permissions are set up right, etc. I'm fairly sure that Apache isn't interfering, since there's nothing in the logs -- what gets me is that I don't see anything on Wireshark, of all things. It's like the phone just plain isn't trying to make the request.

解决方案

maybe it is caching the ajax requests? try setting cache:false in your jquery ajax requests.

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐