0

I have a container, the content was loaded with AJAX.

Inside that container, I have a form, and the plan is to submit the form with AJAX.

I am currently testing the code if this works, but the result turned out to be unexpected results.

Here is the form submission code:

$("#in-quiz-answer").click(function(e) {
    e.preventDefault();
    var ans = $(".answer-rad").val();
    var addr = $("#in-address").val();
    $.ajax({
        type: 'POST',
        url: 'pages/bin/quizprocess.php',
        data: "ans=123",
        success: function(data) {
            alert(data);
        }, 
        error: function(a, b, c) {
            alert("Error pada koneksi: " + a + ", " + b + ", " + c);
        }
    });

    return false;
});

In quizprocess.php i only have echo $_POST['ans']; for testing purposes, but the ajax success function alerts a long html code (my whole page code) instead of just what I expected "123". Can anyone explain why is this happening?

[EDIT] Seems that my problem is it is not even requesting to quizprocess.php but the ajax success. I still don't have any workaround on this.

[SOLUTION] I have found the problem, it is the url rewriteengine from my htaccess that caused the problem. Thank you very much for all the help and comments

user2002495
  • 2,126
  • 8
  • 31
  • 61
  • 1
    I think you need an `.exit()` in PHP to avoid sending the whole HTML: http://stackoverflow.com/questions/2233057/response-end-in-php – Shadow The GPT Wizard Aug 04 '13 at 08:02
  • 2
    if your `quizprocess.php` script contains only `echo $_POST['ans']`, and nothing else, then your ajax request is not retrieving the script. For instance when the server gets a request for the `pages/bin/quizprocess.php` url there might be a redirect to a 404 page or similar. Have you looked at the actual html code that is returned to see what page it is? – Patrick Evans Aug 04 '13 at 08:03
  • @ShadowWizard: it's not working, see my edit part for more details – user2002495 Aug 04 '13 at 08:07
  • have you tried an absolute url path for the script url? since you are using a relative path atm it might not be the correct path. – Patrick Evans Aug 04 '13 at 08:07
  • @PatrickEvans: The code that is returned is my default header code. This header code is exists for my entire web page. – user2002495 Aug 04 '13 at 08:09
  • Thanks for the help, see solution part. – user2002495 Aug 04 '13 at 08:12

0 Answers0