当我尝试提交表单时,我得到一个错误,或者如果我在我的控制台中手动输入它,我会收到此错误:
RangeError: Maximum call stack size exceeded
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
$(document).ready(function() {
$('#contact').on('submit', function(event) {
event.preventDefault();
var valid = 1;
var name = $('input[name$="name"]');
var email = $('input[name$="email"]')
var phone = $('input[name$="phone"]');
var comment = $('input[name$="comment"]');
if (!name.val() && valid == 1) {
valid = 0;
alert('Please fill out the Name field');
name.focus();
}
if (!email.val() && valid == 1) {
valid = 0;
alert('Please fill out the E-mail Address field');
email.focus();
}
if (!phone.val() && valid == 1) {
valid = …Run Code Online (Sandbox Code Playgroud) 我在PHP中有一个foreach循环:
var circle_<?php echo $x; ?> = '<?php echo $c; ?>';
Run Code Online (Sandbox Code Playgroud)
它在JavaScript中返回:
var circle_0 = '<p class="medium">With us, you can customize more than just a closet.</p>';
var circle_1 = '<p class="medium">We are boutique condo builders who love what we do.</p>';
var circle_2 = '<p class="medium">who says condos can't be spacious?<br/></p>';
Run Code Online (Sandbox Code Playgroud)
如您所见,circle_2在字符串中有一个撇号,因此它会破坏脚本:
未捕获的SyntaxError:意外的标记ILLEGAL
我将使用什么过滤器来解决这个问题(PHP或JavaScript)?
可能重复:
$ .post抛出"非法调用"
尝试提交AJAX请求时出现以下错误:未捕获TypeError:非法调用.这是代码:http://pastie.org/private/px6qinlgydv6cgcwrghvxw,如果我删除$ .ajax()函数,问题就会消失.
<script type="text/javascript">
$(document).ready(function() {
$('.inquiry-button').on('click', function(e) {
if($('.x-box ul li').length > 0) {
$('.x-box, .x-box-bottom').fadeOut('slow', function() {
$('.inquiry-form, .inquiry-buttons').fadeIn();
})
}
})
$('.edit-inquiry-submit').on('click', function(e){
e.preventDefault();
$('.inquiry-form, .inquiry-buttons').fadeOut('slow', function() {
$('.x-box, .x-box-bottom').fadeIn();
})
})
$('.inquiry-submit').on('click', function(e) {
e.preventDefault();
var valid = 1;
var name = $('#your_name');
var email = $('#your_email');
var company = $('#company_name');
if (!name.val() && valid == 1) {
var valid = 0;
name.focus();
alert('Please provide your Name');
}
if …Run Code Online (Sandbox Code Playgroud) 我有点懒,只是使用PHP来存储所有这些值,我应该使用Javascript来做到这一点.什么是在Javascript中执行以下操作的最佳方法?然后我会使用jQuery的.each函数来循环它.
$accessories = array (
array('name' => 'Chrome pull out wire Basket 500 & 600 wide ', 'price' => '60'),
array('name' => 'Chrome shoe rack 2 Tier', 'price' => '95'),
array('name' => 'Chrome Shoe Rack 3 Tier', 'price' => '145'),
array('name' => 'Chrome pull out trouser rack', 'price' => '40'),
array('name' => 'Pull out tie rack', 'price' => '135'),
array('name' => 'Pull Down hanging Rail 450mm to 1190mm width', 'price' => '33.50'),
array('name' => 'Corner Hanging Rail', 'price' => '33.50') …Run Code Online (Sandbox Code Playgroud) 这是我的代码:
function validateField(field, input) {
if (field && input) {
$.ajax({
type: 'POST',
url: '<?php echo site_url("ajax/verify"); ?>',
dataType: 'json',
data: { 'field' : field, 'input' : input},
success: function(result) {
var available = result.available;
if (available == 1) {
// return true (for the entire function);
}
}
});
}
return false;
}
Run Code Online (Sandbox Code Playgroud)