我使用Corona SDK中的qrscanner插件扫描QR码并只执行2个功能。首先,它检查数据库中的bool值,如果值为0,它应显示一条消息并将其更改为1.
第一个网络呼叫在应用程序中工作并更新测试,但第二个网络呼叫不返回任何内容。代码如果非常基本,因为它是我的第一个lua / corona脚本。
local json = require( "json" )
local function handleResponse( event )
if not event.isError then
local data,pos,msg= json.decode(event.response)
print( event.response )
if not data then
native.showAlert('error, no response', 'no response from the server', {'OK'})
else
if data.checked_in == "0" then
myText.text = "Not checked in yet.\nVehicle Detail:\nReg#\n"..data.registration.."\nMake:\n"..data.make.."\nModel:\n"..data.model.."\n"
urx2 = "http://mydomain/index.php/checkin/"..message
network.request( urx2, "GET", handleResponse2 )
print('Scanned message:', message)
else
myText.text = "WARNING: Vehicle already checked in.\nVehicle Detail:\nReg#\n"..data.registration.."\nMake:\n"..data.make.."\nModel:\n"..data.model.."\n"
end
end
else
native.showAlert('Darn: this url is broken: '..urx, message, {'OK'})
end
return true
end
local function handleResponse2( event )
if not event.isError then
local data,pos,msg= json.decode(event.response)
print( event.response )
if not data then
native.showAlert('error, no response', {'OK'})
else
if data.checked_in == "0" then
myText.text = "Still not checked in, try again."
else
myText.text = "Successfully checked in."
end
sceneGroup:insert( summary )
print(data.checked_in)
end
end
return true
end
local function status_listener(message)
urx = "http://mydomainindex.php/checkedin/"..message
network.request( urx, "GET", handleResponse )
end
local function checkin_listener(message)
urx = "http://mydomain/index.php/checkin/"..message
network.request( urx, "GET", handleResponse2 )
print('Scanned message:', message)
end
所以一切都达到了这一点:
if data.checked_in == "0" then
myText.text = "Not checked in yet.\nVehicle Detail:\nReg#\n"..data.registration.."\nMake:\n"..data.make.."\nModel:\n"..data.model.."\n"
urx2 = "http://mydomain/index.php/checkin/"..message
network.request( urx2, "GET", handleResponse2 )
print('Scanned message:', message)
我错过了什么?