2008-12-25 161 views
0

我正在使用jQuery和Ajax。jQuery ajax調用javascript函數

我MainFile具有下面的代碼:

<html> 
    <head> 
     <script src="Myscript.js"> 
     </script> 
     <script type="text/javascript"> 
      $(document).ready(function(){ 
       $.ajax({ 
        type: 'POST', 
        url: 'ajax.php', 
        success: function(data){ 
         $("#response").html(data); 
        } 
       }); 
      }); 
     </script> 

    <body> 
     <div id="response"> 
     </div> 
    </body> 
</html> 

我的ajax.php獲取樣本數據

... 
MyScript.js has the following 

function display (text,corner) 
{ 

} 
.. 

我有Myscript.js。在這裏,我有一個叫display(text,corner)的功能。我必須在執行ajax.php後調用這個函數。

如何在jQuery中爲上述代碼執行此操作?

是否可以在ajax.php之後決定執行順序並致電display(text,corner)

回答

1

您應該調用display功能Ajax請求的回調函數,像這樣:

$.ajax({ 
    type:'POST', 
    url: 'ajax.php', 
    success: function(data){ 
     display(data, /* your other parameter, corner */); //Invoking your data function 
    } 
});  

在上述情況下,data是從ajax.php

+0

感謝Dreas格列奇收到響應,現在工作正常 – venkatachalam 2008-12-25 09:21:23