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 }
    
    评论

报告相同问题?