html5 - Get variable from Sencha Touch Ext.data.JSONP.request response -
i'm trying boolean (success) , html string (result) response ext.data.jsonp.request
, can't fgure out how. here's code have far:
ext.data.jsonp.request({ url: 'http://wereani.ml/shorten-app.php', callbackkey: 'callback', params: { data: ext.encode(values) }, success: function(response) { console.log(response); console.log(json.stringify(values)); console.log('link shortened'); if(response.responsetext['success'] == true) { ext.msg.alert('link shortened', response.responsetext, ext.emptyfn); } else { ext.msg.alert('error', response.responsetext, ext.emptyfn); } form.reset(); }, failure: function(response) { console.log(response); console.log(json.stringify(values)); console.log('error'); ext.msg.alert('error', 'please try again.', ext.emptyfn); } });
some sample json-p:
callback({"success":false,"result":"<div class=\"error\">please enter valid link shorten!<\/div>"})
the error i'm getting uncaught typeerror: cannot read property 'success' of undefined
. in advance help!
edit: seems while response
object {success: false, result: "<div class="error">please enter valid link shorten!</div>"}
, response.responsetext
undefined
. using wrong variable? couldn't find documentation on response
.
edit 2: seems reason console.log(response.responsetext)
returning undefined because it.... was. jsonp-encoded variables (success
, result
) passed parsed automatically object, , response.responsetext
never created (though think supposed be). solution read response.success
, response.result
directly!
answer: here's code worked. viswa help!
ext.data.jsonp.request({ url: 'http://wereani.ml/shorten-app.php', callbackkey: 'callback', params: { data: ext.encode(values) }, success: function(response) { if(response.success === true) { ext.msg.alert('link shortened', response.result, ext.emptyfn); } else { ext.msg.alert('error', response.result, ext.emptyfn); } form.reset(); }, failure: function(response) { console.log('error'); ext.msg.alert('error', '<div class="error">please try again.</div>', ext.emptyfn); } });
try this
ext.data.jsonp.request({ url: 'http://example.com/script.php', callbackkey: 'callback', params: { data: ext.encode(values) }, success : function(response) { console.log("spiffing, worked"); // success property console.log(response.success); // result property console.log(response.result); }, failure: function(response) { console.log(response); ext.msg.alert('error', 'please try again.', ext.emptyfn); } });
Comments
Post a Comment