AJAX到JQuery转换协助

时间:2013-03-20 01:03:26

标签: jquery html ajax forms

有人愿意帮我解决这个剧本吗?

我只需要有人拿这个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>

希望这足以让它变得有意义。我当然感谢任何帮助...

1 个答案:

答案 0 :(得分: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 () {

   },
});