Image

Imagecrydown wrote in Imagejavascript

jquery + bind('click') + IE + variables scope

Hi everyone! Need help.

I have the button and jquery .bind('click') on it. in bind I call the fucntion which get an object (inputData) as argument and processes jquery POST to controller. JQuery POST has a callback in which I try to deal with this argument (inputData). But only in IE it already has its property "data" = null. Does anybody know what happening? How can I resolve this problem?

If I try to send POST without bind it work correct..


http://www.crydown.tu2.ru/index.phtml

post.js

function func(inputData) {
var inputData = inputData;
alert('inputData.data.id before POST ' + inputData.data.id);
$.post("controller.php",
{id: inputData.data.id, _action: "test"},
function(data){
alert('data.id from RESPONSE ' + data.id);
alert('inputData.data.id after POST ' + inputData.data.id);
},
'json'
);
}


index.phtml

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../js/jquery-1.2.3.js"></script>
<script type="text/javascript" src="post.js"></script>
</head>
<body>
<input type="button" value="OK" id="send_post">
<script>
var myData = {data: {id: 'sss'}};
func(myData);
$('#send_post').bind('click', {id: 'sss'}, func);
</script>
</body>
</html>



controller.php

<?php
if ($_POST['_action'] == 'test') {
echo json_encode(array('id' => 111));
}
?>



Thanks