views:

99

answers:

1
<script type="text/javascript"> 
var fixed = 1;
var sizew = 122; 
var sizeh = 160; 

    /*
     * function crop()
     * ajax function which returns the cropped image
     */
    function crop() {

        $.ajax({
               type: "POST",
    dataType: 'json',
               url:"functions.php?action=crop",
               data: {x: $('#x').val(),y: $('#y').val(),w: $('#w').val(),h: $('#h').val(),fname:$('#fname').val(),fixed:fixed,sizew:sizew,sizeh:sizeh},
               success: function(response){
                        alert('TEST');
                   if(!fixed)

        $("#showPhoto").css({overflow:"auto"})

                   $("#showPhoto").html($(document.createElement("img")).attr("src",response.filename)).show();
                   $("#showPhoto").after("There you go...").show();
                   $("#image").slideUp();
               }
             });
    }
    </script>

<img id="loading" src="c/assets/loading.gif" style="display:none;">
<div id="showPhoto"></div>
<div id="image" style="display:none;">

<form action="" method="post" id="crop_details">
        <input type="hidden" id="x" name="x" />
        <input type="hidden" id="y" name="y" />
        <input type="hidden" id="w" name="w" />
        <input type="hidden" id="h" name="h" />
        <input type="hidden" id="fname" name="fname"  />
        <input type="button" value="Crop Image" onclick="return crop();" />
</form>

</div>

<div id="upload">
<form id="form1" action="" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file">
<input type="button" id="buttonUpload" value="Upload Image" onClick="return ajaxFileUpload();" />
</form>
</div>   

why doesnt it alert TEST when i run the function? It send the ajaxcall, and get the response.filename back, but it doesnt run anything in success? Not the alert "test" and neither the rest..

But.. it do work when im not including "top.php" at the top of the file.

But what could possibly interrupt this from running the success?

top.php is where it loads title, head javascripts and css files and some javascript functions

UPDATE I made a error handler, and now get this in Firebug:

get channel   "({"filename":"1283548305.jpg"})"(RED)
get statusText   "OK"(RED)
getResponseText  "({"filename":"1283548305.jpg"})"(RED)
constructor(RED)  function()

(RED) means that the text is red.. like thats the error i think.

A: 

Check response.status, what is its value?

aularon
response.status is 200
Karem
whats `response.responseText`?
aularon
({"filename":"1283550713.jpg"})
Karem
do you have an online live version that I can check, cut's it's weird that the page returns 200 status and valid JSON, and still there's an error.
aularon
I tried to change jquery lib from 1.4.2 to 1.3.2 and now it works perfectly?
Karem
that's weird, I'm still interested in knowing what was the problem in the first case.
aularon
metoo, now im trying to find out how to make it work in 1.4.2 as i have other functions on the page that needs the 1.4.2.
Karem
If you can upload the files replicating the problem to some free hosting so we can help debugging.
aularon
the problem was the response was wrapped in ().. I accepted your answer for trying!
Karem
Yes, I was still trying and found that as well. Seems like with jquery 1.4.2 they started to rely on browser's native `JSON.parse` if found, because my firefox's `JSON.parse` is identical, I had to remove () so it works. I classify this as a bug in jQuery, they have to let that parsing error go to the browser so it can be debugged, not hiding it, they probably do a `try{}` around it.
aularon