>
> Here's the top of the html file, the Javascript function and the Python
> file. Started using the *jsonp-2.4.0.min.js* script because it appears to
> handle errors better. I've just jumped into Web2py so I don't know if I'm
> building the URL properly.
>
This returns:
*errMsg =Uncaught Error.*
*undefined*
*status =error*
*xhr.status= undefined*
*xhr.statusText= undefined *
------------------------------------------
{{extend 'layout.html'}}
<head>
<script src="/amrat_dev/static/js/jsonp-2.4.0.min.js"
type="text/javascript"></script>
</head>
<input type="button" name="submit" value="Test" onclick="*getTest3(0)*;" />
.
.
.
function *getTest3(type)* {
var $url = "get_days";
alert("In getTest3 before jsonp call");
var dbugData = "";
$('textarea#retarea').val( $('textarea#retarea').val() + dbugData );
*$.jsonp({*
beforeSend: alert("Before jsonp call"),
url: "get_days",
datatype: 'json',
success: function(json, textStatus, xOptions) {
alert(json.message); //Undefined Error
$('textarea#retarea').val( $('textarea#retarea').val() + "\ntextStatus =" +
textStatus );
$('textarea#retarea').val( $('textarea#retarea').val() + "\njson.status= "
+ json.status );
},
error: function(xhr, status) {
var errMsg;
if (xhr.status === 0) {
errMsg ='Not connect.\n Verify Network.';
} else if (xhr.status == 404) {
errMsg ='Requested page not found. [404]';
} else if (xhr.status == 500) {
errMsg ='Internal Server Error [500].';
} else if (status == 'parsererror') {
errMsg ='Requested JSON parse failed.';
} else if (status == 'timeout') {
errMsg ='Time out error.';
} else if (status == 'abort') {
errMsg ='Ajax request aborted.';
} else {
errMsg ='Uncaught Error.\n' + xhr.responseText;
}
alert(errMsg);
$('textarea#retarea').val( $('textarea#retarea').val() + "\nerrMsg =" +
errMsg );
$('textarea#retarea').val( $('textarea#retarea').val() + "\nstatus =" +
status );
$('textarea#retarea').val( $('textarea#retarea').val() + "\nxhr.status= " +
xhr.status );
$('textarea#retarea').val( $('textarea#retarea').val() + "\nxhr.statusText=
" + xhr.statusText );
}
});
}
Here's the server side code:* json_test.py:*
# coding: utf8
# try something like
def index(): return dict(message="hello from json_test.py")
import sys,subprocess
import datetime
import gluon.contrib.simplejson
def call2():
session.forget()
return service()
@service.json
def get_days():
return ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"]
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.