2013-03-20 89 views
0

任何人都愿意帮我解决这个脚本吗?AJAX to JQuery Conversion Assistance

我只需要有人把这个片段的AJAX,基本上用jQuery重新编程,所以我可以学习它,并学习更多关于如何使用jQuery。这是我目前正在使用的AJAX工作原理,我认为如果我能在jQuery中看到它,它会启动我的学习过程...

因此,如果任何人都会如此善良,这是脚本:

function CreateXmlHttpObject() { //function to return the xml http object 
    var xmlhttp = false; 
    try { 
     xmlhttp = new XMLHttpRequest(); //creates a new ajax object 
    } catch(e) { 
     try { 
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); //this is for IE browser 
     } catch(e) { 
      try { 
       req = new ActiveXObject("Msxml2.XMLHTTP"); //this is for IE browser 
      } catch(e1) { 
       xmlhttp = false; //error creating object 
      } 
     } 
    } 
    return xmlhttp; 
} 

function getMetaID(strURL) { 
    var req = CreateXmlHttpObject(); // function to get xmlhttp object 
    if(req) { 
     req.onreadystatechange = function() { 
      if(req.readyState == 4) { //data is retrieved from server 
       if(req.status == 200) { // which reprents ok status      
        document.getElementById('meta_id').innerHTML = req.responseText; //put the results of the requests in or element 
       } else { 
        alert("There was a problem while using XMLHTTP:\n"); 
       } 
      } 
     } 
     req.open("GET", strURL, true); //open url using get method 
     req.send(null); //send the results 
    } 
} 

这是调用函数(PHP)的网页上:

echo '<select name="meta_id" onChange="getMetaID('."'".'http://www.mysite.com/backoffice/meta_tags/ajaxpageid.php?meta_id='."'".'+this.value)">'; 

这之后,一个<div>

希望这是足够的信息,让它有意义。当然,我感谢所有帮助...

回答

0
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script> 

使用jQuery

$.ajax(serverUrl, { 
    type: "POST", 
    data:{ strURL:strUR}, 
    statusCode: { 
     200: function (response) {   
     }, 
     201: function (response) {   
     }, 
     400: function (response) { 
     }, 
     404: function (response) { 
     ); 
     } 
    }, success: function() { 

    }, 
}); 
之前添加这些文件