weixin_33714884 2014-05-14 06:45 采纳率: 0%
浏览 54

ajax意外令牌*

I have ajax script but it returns unexpected token *. I use ajax example from w3school.com and it different from usually. This is my script:

<script>  
$("#conform").click(function ()
{
   var a= $(this).closest(".col").prev().find("#prod_qty").val();
   var b= $(this).prev().val();
   var c= $(this).closest("#highlight_product").find("#name").val();
   var d= b * c;
   var e= "<?php echo $_SESSION['name'] ?>";
   var f= "<?php echo $_SESSION['email'] ?>";
}
)

    function buy() 
    {   
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null)
     {
     alert ('Browser does not support HTTP Request');
     return;
     }
    var url='buy.php?user='+e+'&email='+f+'&product='+c+'&count='+a+'&total='+d;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open('GET',url,true);
    xmlHttp.send(null);*/
    }

    function stateChanged() 
    { 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete')
     { 
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
     }
    }

    function GetXmlHttpObject()
    {
    var xmlHttp=null;
    try
     {
     // Firefox, Opera 8.0+, Safari
     xmlHttp=new XMLHttpRequest();
     }
    catch (e)
     {
     //Internet Explorer
     try
      {
      xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
      }
     catch (e)
      {
      xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
      }
     }
    return xmlHttp;

}

I try find it in google, It says problem with dataType, It must HTML. But i dont know how to change it, anyone know?

  • 写回答

2条回答 默认 最新

  • weixin_33743248 2014-05-14 06:47
    关注

    Can I suggest using Jquery AJAX wrapper? It's cross browser compliant, much neater and lets gives you a handy callback function on completion(really important) since the result is ASYNC which allows you to retrieve data before execution.

    $.ajax({
        type: "POST",
        url: '',
        data : '',
        dataType: 'JSON',
        }).done(function(data) {
     // this will be run when the AJAX request completes
        var ParsedData= jQuery.parseJSON(data);
        // this will be run when the AJAX request succeeds
    }).fail(function() {
        // this will be run when the AJAX request fails
    }).always(function() {
        // this will be run when the AJAX request is complete, whether it fails or succeeds
    });
    
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭