ajax javascript

60 views
Skip to first unread message

eric cuver

unread,
Jun 7, 2016, 5:40:28 PM6/7/16
to brython
hi everybody

how I can use the ajax javascript with brython

 var xhttp = new XMLHttpRequest()
 i test window.XMLHttpRequest but doesnt work because the "new"

thank you

Kiko

unread,
Jun 8, 2016, 2:20:42 AM6/8/16
to bry...@googlegroups.com
The following code should work

from browser import window
from javascript import JSConstructor

xhttp = JSConstructor(window.XMLHttpRequest)()



--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To post to this group, send email to bry...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/brython/6cad222b-d4ad-41d1-ae6d-4df550081792%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

eric cuver

unread,
Jun 8, 2016, 3:05:10 AM6/8/16
to brython
cool it's work i finish today apple/android/window phone application coding entirely Brython !!!!

Kiko

unread,
Jun 8, 2016, 3:15:46 AM6/8/16
to bry...@googlegroups.com
2016-06-08 9:05 GMT+02:00 eric cuver <amihaco...@gmail.com>:
cool it's work i finish today apple/android/window phone application coding entirely Brython !!!!


Great, if it is possible to have a demo it would be great.
We could add this to the brython gallery or to the 'brython in the wild' wiki (https://github.com/brython-dev/brython/wiki/Brython%20in%20the%20wild).


 

eric cuver

unread,
Jun 8, 2016, 3:28:18 AM6/8/16
to brython
yes  it is an application I have to put everything online tonight I am sending you the link is an application for a startup

Kiko

unread,
Jun 8, 2016, 3:44:55 AM6/8/16
to bry...@googlegroups.com
2016-06-08 9:28 GMT+02:00 eric cuver <amihaco...@gmail.com>:
yes  it is an application I have to put everything online tonight I am sending you the link is an application for a startup

Cool, let's see the final result of your hard work!!
 

eric cuver

unread,
Jun 8, 2016, 4:19:10 AM6/8/16
to brython
on android 4.0

xhttp = JSConstructor(window.XMLHttpRequest)()
it give me this error :
Internal javascript error : TypeError : <TypeError: cannot call method 'apply' of undefined

Kiko

unread,
Jun 8, 2016, 4:24:12 AM6/8/16
to bry...@googlegroups.com
2016-06-08 10:19 GMT+02:00 eric cuver <amihaco...@gmail.com>:
on android 4.0

xhttp = JSConstructor(window.XMLHttpRequest)()
it give me this error :
Internal javascript error : TypeError : <TypeError: cannot call method 'apply' of undefined

Are you using a WebView?
 

eric cuver

unread,
Jun 8, 2016, 4:39:10 AM6/8/16
to brython
yes it's webview cordova android 4.1.1 

Kiko

unread,
Jun 8, 2016, 5:07:00 AM6/8/16
to bry...@googlegroups.com
2016-06-08 10:39 GMT+02:00 eric cuver <amihaco...@gmail.com>:
yes it's webview cordova android 4.1.1 

Uff, I have not idea about that. I don't know if it uses chrome, the android browser, other stuff under the hood.

I tried the following example (http://jsfiddle.net/23u56ct9/) on my android (v4.4.4) with chrome and it doesn't work but it works with FF on the same mobile. But with the mobile I can't debug anything.

I can't dive more now (I'm working).

Did you imported window?

from browser import window
 

eric cuver

unread,
Jun 8, 2016, 5:54:04 AM6/8/16
to brython
brython 3.2.6 on Netscape 5.0 (linux; u; android 4.1.1; fr-fr; cink peax build / jr003c) applewebkit/534.30 (khtml, like gecko) version/4.0 mobile safari/534.30

yes i made : 
from browser import window




Le mercredi 8 juin 2016 11:07:00 UTC+2, kiko (on pybonacci) a écrit :




yes  

eric cuver

unread,
Jun 8, 2016, 6:18:28 AM6/8/16
to brython
when I call a script javascript ajax from Brython it works but it's not great I have less control over my ajax calls

Kiko

unread,
Jun 8, 2016, 6:21:05 AM6/8/16
to bry...@googlegroups.com
2016-06-08 12:18 GMT+02:00 eric cuver <amihaco...@gmail.com>:
when I call a script javascript ajax from Brython it works but it's not great I have less control over my ajax calls

if you use window.XMLHttpRequest you should have similar control as you are using the JS object directly...
 

eric cuver

unread,
Jun 8, 2016, 9:27:46 AM6/8/16
to brython
look if i code that it work :

function Get (emailval, passwordval) {

var req = new XMLHttpRequest();
 loadingdiv = document.getElementById('loading');
loadingdiv.style.display = "block";
req.open("GET", 'xxxxxxxxxxxx + email + password , false);
req.onreadystatechange = function (aEvt) {
  if (req.readyState == 4) {
     if(req.status == 200)
   document.getElementById("resultat").innerHTML=  req.responseText '),
    


     else
      document.getElementById("resultat").innerHTML="Erreur pendant le chargement de la page",
      alert(req.responseText) 
    

}
else {


}

};
req.send(null);





// body...  
}



brython code

from browser import alert, window
from javascript import JSConstructor

rectangle = JSConstructor(window.Get)
Get(password, email)

but this code doesent work

Pierre Quentel

unread,
Jun 8, 2016, 11:21:29 AM6/8/16
to brython


Le mercredi 8 juin 2016 12:21:05 UTC+2, kiko (on pybonacci) a écrit :


2016-06-08 12:18 GMT+02:00 eric cuver <amihaco...@gmail.com>:
when I call a script javascript ajax from Brython it works but it's not great I have less control over my ajax calls

if you use window.XMLHttpRequest you should have similar control as you are using the JS object directly...
 

This may be related to issue #373 : for some browsers, XMLHttpRequest is not a function, and in this case
using JSConstructor fails. You should try to use the Brython ajax module instead of window.XMLHttpRequest
 

eric cuver

unread,
Jun 8, 2016, 1:31:33 PM6/8/16
to brython
dans ce cas il faut que j'installe le server brython pour que l'ajax fonctionne  vue que je suis en local sur l'application ?

eric cuver

unread,
Jun 8, 2016, 2:55:11 PM6/8/16
to brython
in this case I have to install the server Brython works for the ajax view I am local to the web application?


Le mercredi 8 juin 2016 17:21:29 UTC+2, Pierre Quentel a écrit :

Pierre Quentel

unread,
Jun 8, 2016, 3:44:39 PM6/8/16
to brython


Le mercredi 8 juin 2016 19:31:33 UTC+2, eric cuver a écrit :
dans ce cas il faut que j'installe le server brython pour que l'ajax fonctionne  vue que je suis en local sur l'application ?
Non, par contre il faut intégrer Brython par <script src="brython_dist.js"> pour améliorer le chargement des modules, dont ajax.

eric cuver

unread,
Jun 9, 2016, 5:57:42 AM6/9/16
to brython
Il existe une version mimifier de ce brython JS car il gros et lent au chargement

eric cuver

unread,
Jun 9, 2016, 8:32:38 AM6/9/16
to brython
je pense que je vais plutot utilise JQUERY  avec le POST ET GET
comme ça 
jq = window.jQuery.noConflict(True)
jq= jq("div")
Reply all
Reply to author
Forward
0 new messages