weixin_33690963 2015-03-28 08:13 采纳率: 0%
浏览 15

Ajax发布返回HTML

I have this ajax function (refer below)

$.ajax({
    url: "processor.php",
    type:"POST",
    data: { 'id' : "itemid, 'itemname' : itemname, 'itemdesc' : itemdesc" } ,
    success:function(e){
        if(($.trim(e) == "success")){
            alert("success");
        }else{
            alert(e);
        }  
    },error:function(){
        alert("critical error");
    }
});

assume that I already have the linked script of jquery and the content of those variables that has been declared on the data argument inside ajax function. Now I have a processor.php (refer below)

//this is the processor php
echo "success";

so base from above references, the ajax function submit a post request to processor.php and then the processor.php will respond "success" string as declared with the "echo success" but what happen is it doesn't get the success response instead the whole html tags on the current page is pop up (alert), why?? any ideas, clues, recommendation, suggestion would be greatly appreciated. Thank you.

PS: i know the response is not success but why it popup (alert) the whole html tags in the current page?

  • 写回答

3条回答 默认 最新

  • weixin_33704591 2015-03-28 08:28
    关注

    there is syntax error in posted data and you probably have a redirect to new page instead of processor.php.

    EDIT

    Also make sure that processor.php returns only the word "success" and there is no more html tags in the source of page.

    wrong syntax:

    data: { 'id' : "itemid, 'itemname' : itemname, 'itemdesc' : itemdesc" }
    

    suggested change:

    data: { id : itemid, itemname : itemname, itemdesc : itemdesc }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染