首页 \ 问答 \ do块内输入'< - '的解析错误?(Parse Error on Input '<-' inside a do block?)

do块内输入'< - '的解析错误?(Parse Error on Input '<-' inside a do block?)

我正在尝试使用Parsec在Haskell中进行一些解析。 我的代码中有很多解析器,但是其中一个解析器出错了:

expression2 =
    do (operator lexer "|"
        a <- alternate
        as <- expression2
        return $ a:as
  ) <|> return []

错误是parse error on input '<- ,在a <- alternate行上的parse error on input '<-

任何人都可以解释为什么我收到此错误,以及如何解决它?

提前致谢。


I'm trying to do some parsing in Haskell using Parsec. I've got a number of parsers in my code, but am getting an error on one of them:

expression2 =
    do (operator lexer "|"
        a <- alternate
        as <- expression2
        return $ a:as
  ) <|> return []

The error is parse error on input '<-, on the a <- alternate line.

Can anyone explain why I'm getting this error, and how to fix it?

Thanks in advance.


原文:https://stackoverflow.com/questions/5891654
更新时间:2023-01-22 19:01

最满意答案

为什么你在锚中写ss.php你不需要那就是为什么它在点击时重定向ss.php并获得错误未定义的索引。

你的HTML代码应该是这样的:

<form id="myForm" method="post" action="ss.php">
    <div class="img">            
        <img id="theme_bg" src="images/themes/theme1.jpg">
        <input name="imgpath" id="imgpath" type="hidden"/>
    </div>
</form>

Jquery代码:

$(document).ready(function ($) {
        $('.img').on('click', 'img', function () {
            var imgsrc = $(this).attr('src');
            $("#imgpath").val(imgsrc);       //this is returning the img src correctly 
            $("#myForm").submit();
        });
});

ss.php

 <?php
   $imagepath = $_POST['imgpath'];
   echo $imagepath;
?>

Why you wrote ss.php in anchor you dont need that that's why it redirecting ss.php on click and getting error undefined index.

Your html code should be like this:

<form id="myForm" method="post" action="ss.php">
    <div class="img">            
        <img id="theme_bg" src="images/themes/theme1.jpg">
        <input name="imgpath" id="imgpath" type="hidden"/>
    </div>
</form>

Jquery code:

$(document).ready(function ($) {
        $('.img').on('click', 'img', function () {
            var imgsrc = $(this).attr('src');
            $("#imgpath").val(imgsrc);       //this is returning the img src correctly 
            $("#myForm").submit();
        });
});

ss.php

 <?php
   $imagepath = $_POST['imgpath'];
   echo $imagepath;
?>

相关问答

更多
  • 将dataType: "json",更改为dataType: "text", 您的服务器返回的数据不是有效的JSON。 dataType设置不是针对您要发送到服务器的数据,而是针对服务器返回的数据,这意味着解析错误是指msg而不是data 让success回调中唯一的陈述是: console.log( msg ); 确认返回的数据结构后,请相应地更新success处理程序中的逻辑和dataType值。 Change dataType: "json", to dataType: "text",. The d ...
  • 问题是你正在将data转换为json,但是wp期望一个名为action的字段来找到正确的函数,因此你的返回值是0(找不到函数,没有遇到退出,所以0返回)。 在这种情况下,你实际上不需要json值发送表单,但它会期望一个json响应所以在你的php函数中你应该json_encode你的返回值。 jQuery(document).ready(function(){ var url = ""; ...
  • $.ajax({ url: '/controller', type: 'POST', data:{action:'login',username:username,password:password}, success: function(return_login) { $('#return_login').html(return_login ...
  • 您的问题是关于参数名称在jquery中,参数定义为: var form_data = { 'customer_name' : $('#sds_sender_name').val(), 'customer_email' : $('#sds_sender_email').val(), 'email_subject': $('#sds_email_subject').val(), 'enquiry': $('#sds_sender_enquiry').val() }; 在PHP中 ...
  • 只要服务器端脚本发送HTTP状态码200,它总是会触发success回调。 答案根本不重要。 只有状态码。 在你显示的所有示例中,你都发送了HTTP状态码200 =>成功回调将始终触发。 您可以使用http_response_code函数强制状态码为不同于200的状态码。 作为替代方案,您可以让PHP脚本返回一些信息,然后在成功函数中测试脚本返回的值,以了解某些服务器端处理是否失败: $.ajax({ data: $this.serialize(), type: "POST", ur ...
  • 它返回到jquery,jquery丢弃它。 如果要在加载某些内容之前停止代码,请使用同步ajax。 但这使得页面在ajax请求完成之前没有响应,所以请不要这样做! 同步ajax的示例(不带jquery): var ajax=new XMLHttpRequest(); ajax.open("GET", url, false); ajax.send(null); return ajax.responseText; 注意:对于IE兼容性,这有点复杂,这只是一个概念证明。 这将是jquery这样做的方式: 我如何 ...
  • 您应该使用json或xml格式并解析它,并获取变量。