Вот код:
<script type="text/javascript">
$.ajaxSetup ({
cache: false
});
var ajax_load = "<img src='load.gif' alt='Loading...' />";
$('#create').submit(function() {
$("#result").html(ajax_load);
$.get("actions/create.php", { url: longform },
function(data){
$('#result').html(data);
});
);
});
</script>
Но все, что происходит, это то, что URL в адресной строке меняется на:
http://domain.com/?longform=http://www.google.com/&submit=Submit
Форма и результат div:
<form name="create" action="" id="create">
<input type="text" name="longform" /> <input type="submit" name="submit" value="Submit" />
</form>
<div id="result">
results go here
</div>
Нужно ли иметь код ajax в разделе head?Или это не имеет значения ..
ОБНОВЛЕНИЕ :
Код на моей странице теперь выглядит так:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript">
$.ajaxSetup ({
cache: false
});
var ajax_load = "<img src='img/load.gif' alt='loading...' />";
$('#create').submit(function() {
event.preventDefault();
$("#result").html(ajax_load);
$.get("actions/create.php", { url: longform },
function(data){
$('#result').html(data);
});
);
});
</script>
</head>
<body>
<form name="create" action="" id="create">
<input type="text" name="longform" /> <input type="submit" name="submit" value="Shorten" />
</form>
<div id="result">
123
</div>
По-прежнему не работает.actions / create.php просто выводит строку foobar, чтобы проверить ее.
UPDATE :
Я также пробовал это:
$('#create').submit(function() {
var formdata = $(this).serialize();
$.ajax({
url: 'actions/create.php',
data: formdata,
success: function(responseText){
$('#result').html(responseText);
}
});
return false;
});
Но это также не работает .. может ли что-то в моем htaccess возиться с этим?