in the version 1.64.3, I rivise the function:
function ajax(u,s,t) {
var query="";
for(i=0; i<s.length; i++) {
if(i>0) query=query+"&";
query=query+encodeURIComponent(s[i])+"="+encodeURIComponent(document.getElementById(s[i]).value);
}
jQuery.ajax({type: "POST", url: u, data: query, success: function(msg) {
document.getElementById(t).innerHTML=msg;$("#tables").tablesorter();} });
}
It works,:)
Can we modified function prototype?
function ajax(u,s,t,cmd) {
var query="";
for(i=0; i<s.length; i++) {
if(i>0) query=query+"&";
query=query+encodeURIComponent(s[i])+"="+encodeURIComponent(document.getElementById(s[i]).value);
}
jQuery.ajax({type: "POST", url: u, data: query, success: function(msg) {
if(t==':eval') {eval(msg)}; else{
document.getElementById(t).innerHTML=msg;eval(cmd); } });
}
cmd can call the js code in the "ajax request"
mdipierro 写道:
> If you make an ajax request the JS code inside the HTML is NOT
> executed. This is not a web2py issue. That is how AJAX works. Here is
> a possible workaround.
>
> http://www.daniweb.com/forums/thread53137.html
>
> Massimo
>
>
> On Jul 8, 8:39 pm, zhang zheng <[email protected]> wrote:
>
>> the right is div's id.
>>
>> for example:
>>
>> in controller
>> ////////////////start/////////////////////////
>> def index():
>> return dict()
>> def get_info():
>> return dict()
>> ////////////////end/////////////////////////
>> in view
>> index.html
>>
>> {{extend 'layout.html'}}
>> <a href="#" onclick="ajax('get_info',[],'right');">info</a>
>> <div id="right">display info</div>
>>
>> get_info.html
>> <html>
>> <head>
>> <script>alert('test')</script>
>> </head>
>> <body>
>> this is a test
>> </body>
>> </html>
>>
>> "alert('test')" don't run
>>
>> 2009/7/9 mdipierro <[email protected]>
>>
>>
>>
>>
>>
>>
>>> No problem with the english. I need to see and example else I do not
>>> know what 'right' is.
>>>
>>> Massimo
>>>
>>> On Jul 8, 7:34 am, 张峥 <[email protected]> wrote:
>>>
>>>> hello,all:
>>>>
>>>> IN web2py, I want to use ajax("body_2_5",[],"right"); to display a page.
>>>> but javascript function in the page can't run
>>>>
>>>> The problem may be innerHTML,
>>>> can you help me
>>>>
>>>> my English was poor,sorry!!
>>>>
>> --
>> 张峥
>>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---