Php 为什么使用ajax插件发布表单会在控制台中给出结果,而不会将表单发布到服务器?
我正在使用一个插件劫持一个表单,并通过插件中的ajax函数发布它。我可以发布表单并在控制台中获得结果,但我无法让表单发布并正常工作 我当前的版本正在使用: Laravel-PHP框架 Instagram PHP类-使用PHP与Instagram api交互 Ajax插件-无需页面刷新即可发布表单 目前,我为ajax代码(插件)提供了以下内容: 在我的functions.js文件中,我有以下代码发布表单:Php 为什么使用ajax插件发布表单会在控制台中给出结果,而不会将表单发布到服务器?,php,javascript,jquery,ajax,jquery-plugins,Php,Javascript,Jquery,Ajax,Jquery Plugins,我正在使用一个插件劫持一个表单,并通过插件中的ajax函数发布它。我可以发布表单并在控制台中获得结果,但我无法让表单发布并正常工作 我当前的版本正在使用: Laravel-PHP框架 Instagram PHP类-使用PHP与Instagram api交互 Ajax插件-无需页面刷新即可发布表单 目前,我为ajax代码(插件)提供了以下内容: 在我的functions.js文件中,我有以下代码发布表单: $(document).ready(function() { $('.forms'
$(document).ready(function() {
$('.forms').each(function() {
$(this).formSubmit({
// Shows the formData that will be submitted; return false
// to prevent the form from being submitted
before: function(formData) {
if( console ) {
console.log('`before` callback:');
console.log(formData);
}
},
// Shows the AJAX response when the form is accepted
success: function(data) {
if( console ) {
console.log('`success` callback:');
console.log(data);
}
},
// Shows the AJAX response when the form is rejected
error: function(data) {
if( console ) {
console.log('`error` callback:');
console.log(data);
}
},
// Shows the AJAX error if one occurs
ajaxError: function(textStatus, errorThrown) {
if( console ) {
console.log('`ajaxError` callback:');
console.log(textStatus);
console.log(errorThrown);
}
},
// These add and remove a custom class called 'whoops' to the
// parent element of all invalid fields
showInvalid: function() {
$(this).parent().addClass('whoops');
},
hideInvalid: function() {
$(this).parent().removeClass('whoops');
}
});
});
});
下面是环绕图像的表单标记,这样您就可以通过instagram api从表单提交中发送“喜欢/不喜欢”
try {
$instagram = new Instagram\Instagram;
$instagram->setAccessToken($_SESSION['instagram_access_token']);
$token = $_SESSION['instagram_access_token'];
//$clientID = $_SESSION['client_id'];
$current_user = $instagram->getCurrentUser();
$tag = $instagram->getTag('folkclothing');
$media = $tag->getMedia(isset($_GET['max_tag_id']) ? array( 'max_tag_id' => $_GET['max_tag_id'] ) : null);
$liked_media = $current_user->getLikedMedia();
/* echo 'https://api.instagram.com/v1/media/'. $item->getId() .'/likes?access_token='.$token.''; */
if ( isset( $_POST['action'] ) ) {
echo '<br/>FORM IS SUBMITTED, INSPECT WHAT WAS SENT';
print_r($_POST);
$id = $_POST['id'];
switch( strtolower( $_POST['action'] ) ) {
case 'like':
$current_user->addLike( $id );
break;
case 'unlike':
$current_user->deleteLike( $id );
break;
}
}
} catch ( Exception $e ) {
// yes there is an error
$error = $e->getMessage();
}
echo '<section id="images">';
foreach ( $media as $item ) {
echo '<article class="instagram-image">';
echo '<form class="forms" action="'; echo URL::current(); echo '" method="post">';
$id = $item->getId();
echo '<a title="' . $item->getCaption() .'" class="fancybox" href="' . $item->link . '"><img alt="' . $item->getCaption() .'" src="' . $item->images->standard_resolution->url . '" /></a>';
echo '<div class="formSubmit-feedback"></div>';
echo '<img src="/public/img/377.gif" alt="loader"/>';
if ( $current_user->likes($item) ){
echo '<button class="ajax instabtn unlike icon-heart" type="submit" name="action" value="Unlike"></button>';
} else {
echo '<button class="ajax instabtn like icon-heart" type="submit" name="action" value="Like"></button>';
}
echo '<input type="hidden" name="id" value="'; echo $id; echo '">';
echo '<p>'; echo $item->likes->count; echo '</p>';
echo '</form>';
echo '</article>';
}
echo '</section>';
我知道它离我很近,但我不知道从哪里可以找到它。我是不是读得太快了?它将所有状态函数显示为发布到
控制台.log
。你需要在之前更改你的,成功
等等,才能真正完成文章。好吧,如果我想用成功函数发布文章,那么它就像一篇普通的ajax文章,对吗?只需传入表单数据就可以了?似乎您甚至没有ajax帖子。当您制作一篇ajax文章时,您将在文章中使用这些状态。看看这个:阅读AJAX并为调用找到一个位置。然后,当您陷入困境时,可以提出另一个问题,这不是一个错误,这是您为ajax调用的before事件设置的日志,您在控制台中是否收到任何其他消息?检查浏览器开发工具的“网络”选项卡并分析ajax调用ajax调用通过并起作用,因为在标题选项卡中可以看到其中的表单id。你认为可能是Ajax插件没有传递到正确的URL吗?
`before` callback: functions.js:51
Object {id: "509073517011482478_5670460"}