I have a php page with the follow javascript code in it:
$("#saveButton").click(function() {
HLalert('Saving...');
$.getJSON("<?php echo $PHP_SELF; ?>", {
ajax: 1,
classes: $("#alllessons").serialize()
}, function(output) {
if (output.status == false) { HLalert(output.message); }
else { HLalert('Saved!.'); }
});
});
For whatever real it does not work. The javascript before and after it exectute but these seemingly does not. Not even a failed status is returned.
HLalert() is a function that displays a twitter like alert message.
At the top of the php page I have the code
<?php
if ($_GET['ajax'] == 1) {
// parse the ajax values
// output json and die
}
// regular page code
I tried changing the names of the passed values in the getJSON call, that doesn't do anything. I've tried putting the page the getJSON calls into a different file and that doesn't do anything either.
Is there something fundamentally wrong with my getJSON code that I just cannot see? Are you allowed to make $.ajax calls to your self-page?
Tha开发者_开发知识库nks
do you mean $_SERVER['PHP_SELF']
? I am not really sure if there is a $PHP_SELF
.
do you mean document.location ? ;-) No need for PHP here.
$PHP_SELF
does not exist unless you have defined it.
Do you perhaps mean $_SERVER['PHP_SELF']
?
Edit: .serialize()
returns a string without quotes and I think the values of your key - value pairs do need to be quoted so perhaps it should be something like:
after the first alert:
var values = '"' + $("#alllessons").serialize() + '"';
and later:
ajax: 1,
classes: values
精彩评论