admin管理员组文章数量:1315942
I am having the following jQuery script.
And getting the error:
SyntaxError: Unexpected end of input
My js file is correct on syntax side, do not missing any closing or opening bracket. Thanks for any suggestion.
I am having the following jQuery script.
http://www.codeshare.io/aQxBp
And getting the error:
SyntaxError: Unexpected end of input
My js file is correct on syntax side, do not missing any closing or opening bracket. Thanks for any suggestion.
Share Improve this question asked Apr 1, 2015 at 20:20 Richard ZilahiRichard Zilahi 6922 gold badges12 silver badges25 bronze badges 9-
1
Try removing the "codeshare.io/new" from
}http://www.codeshare.io/new
– KJ Price Commented Apr 1, 2015 at 20:23 -
ah wel, it seems i do not get your point. you entered
http://www.codeshare.io/new
should i remove what again, please? – Richard Zilahi Commented Apr 1, 2015 at 20:28 - It appears your code is working now. You had that url unmented in your code. That would cause your error. – KJ Price Commented Apr 1, 2015 at 20:32
-
btw, there is no problem with the if includes the
#emailtoinvite
the problem is still occurs when that code snippet is removed. – Richard Zilahi Commented Apr 1, 2015 at 20:32 - actually that url was not added by me. idk how is that got it there. :) check it now: codeshare.io/aQxBp – Richard Zilahi Commented Apr 1, 2015 at 20:34
2 Answers
Reset to default 6The here is that you are telling your ajax call to expect to receive JSON. When JSON is not received, an error will be thrown when JSON.parse tries to parse a non-JSON string. JSON is fairly simple in nature but you have to be intentional. To make an ajax call similar to this (note response.emailtoinvite
):
jQuery.ajax({
type: "POST", // HTTP method POST or GET
url: "sendinvitation.php", //Where to make Ajax calls
dataType: "json", // Data type, HTML, json etc.
data: myData, //Form variables
success: function(response) {
alert(response.emailtoinvite);
},
error: function(xhr, ajaxOptions, thrownError) {
//$(".btn.btn-primary").show(); //show submit button
alert(thrownError);
}
});
....sendinvitation.php will have to send back a proper JSON string. The following works:
{emailtoinvite: "[email protected]", idToInvite: 136}
Important things to note here, all strings must be wrapped in double quotation marks ""
. Also, the entire string must be wrapped in {}
. numbers can be left without quotes around them.
Also important to note that the above is not proper syntax, but does sometimes work. Proper syntax also requires you to wrap you "keys" in quotes ""
as well:
{"emailtoinvite": "[email protected]", "idToInvite": 136}
$.ajax({
type: 'POST',
dataType: 'JSON',
url:"test.php",//<?php echo $_GET['url'] ?>,
data: data,
success: function(response) {
if ($('#toggle').prop('checked')) {
$('.led-<?php echo $_GET[\'color\'] ?>').show();
$('.led-off').hide();
} else {
$('.led-<?php echo $_GET[\'color\'] ?>').hide();
$('.led-off').show();
}
},
});
本文标签: javascriptUnexpected end of input jquery using ajaxStack Overflow
版权声明:本文标题:javascript - Unexpected end of input jquery using ajax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741994556a2409780.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论