如何删除错误“未捕获的语法错误:JSON 中位置 0 的意外标记 S”?

我引用了 SO 的 sols,但没有解决这个错误。

我有一个dashboard.html带有搜索条件的文件,点击它会调用loadtable.js,这个loadtable.js文件使用search.php从表中检索行,

但是有一些错误Uncaught SyntaxError: Unexpected token S in JSON at position 0我也不想在客户端显示服务器返回的 JSON。相反,我想显示表格并将值放入其中。我附上两者loadtable.jssearch.php代码。


http://img3.mukewang.com/62d279730001cd9714310603.jpg

在dashboard.html我有如下代码


 <!-- View Main Lead Table with Filters  -->

            <section class="operation" id="view_lead_info" style="display: none;">


                <!-- Filters -->


                <div class="row">                


                            <div class="col">

                                <label><p><b>Select Filter</b></p></label>                    

                            </div>          


                </div>



                <form action='' method='POST' class='filterformpost' id='filterformpost'>


                    <div class="row">

                        <div class="col span-1-of-4">

                            <div class="row">

                                <div class="col span-1-of-4">

                                    Lead Status:

                                </div>


炎炎设计
浏览 234回答 1
1回答

BIG阳

您返回的不仅仅是您想要的 jsonsearch.php尝试删除这些行:&nbsp; &nbsp; echo $selectSQL;&nbsp; &nbsp; echo "<p></p>";&nbsp; &nbsp; echo "<p></p>";对于前端的 json 输出:您的 js 文件中有 2 个 ajax 调用,第一个将 json 与类一起放入 divmessage_box结果不变:结果来自第二个 ajax 调用,它不会发送您的表单数据。尝试将您的 js 更改为:$(document).ready(function() {&nbsp; &nbsp; var delay = 1000;&nbsp; &nbsp; // Campaign Submit Info&nbsp; &nbsp; $('[name="search_submit"]').click(function(e) {&nbsp; &nbsp; &nbsp; &nbsp; e.preventDefault();&nbsp; &nbsp; &nbsp; &nbsp; var lead_status = $('#filterformpost').find('#lead_status_select option:selected').val();&nbsp; &nbsp; &nbsp; &nbsp; var campaign_status = $('#filterformpost').find('#campaign_status_select option:selected').val();&nbsp; &nbsp; &nbsp; &nbsp; var company_name = $('#filterformpost').find('#company_name_select option:selected').val();&nbsp; &nbsp; &nbsp; &nbsp; var tech_area = $('#filterformpost').find('#tech_area_select option:selected').val();&nbsp; &nbsp; &nbsp; &nbsp; var firm_size = $('#filterformpost').find('#firm_size_select option:selected').val();&nbsp; &nbsp; &nbsp; &nbsp; var firm_type = $('#filterformpost').find('#firm_type_select option:selected').val();&nbsp; &nbsp; &nbsp; &nbsp; var country_name = $('#filterformpost').find('#country_name_select option:selected').val();&nbsp; &nbsp; &nbsp; &nbsp; var state_name = $('#filterformpost').find('#state_name_select option:selected').val();&nbsp; &nbsp; &nbsp; &nbsp; var start_date = $('#filterformpost').find('#start_date_search').val();&nbsp; &nbsp; &nbsp; &nbsp; var end_date = $('#filterformpost').find('#end_date_search').val();&nbsp; &nbsp; &nbsp; &nbsp; console.log(lead_status)&nbsp; &nbsp; &nbsp; &nbsp; console.log(campaign_status)&nbsp; &nbsp; &nbsp; &nbsp; console.log(company_name)&nbsp; &nbsp; &nbsp; &nbsp; console.log(tech_area)&nbsp; &nbsp; &nbsp; &nbsp; console.log(firm_size)&nbsp; &nbsp; &nbsp; &nbsp; console.log(firm_type)&nbsp; &nbsp; &nbsp; &nbsp; console.log(country_name)&nbsp; &nbsp; &nbsp; &nbsp; console.log(state_name)&nbsp; &nbsp; &nbsp; &nbsp; console.log(start_date)&nbsp; &nbsp; &nbsp; &nbsp; console.log(end_date)&nbsp; &nbsp; &nbsp; &nbsp; $.ajax({&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type: "POST",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // url: "https://tribalyze.com/CRM/server/login.php",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; url: "search.php",&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; data: {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "lead_status": lead_status,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "campaign_status": campaign_status,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "company_name": company_name,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "tech_area": tech_area,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "firm_size": firm_size,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "firm_type": firm_type,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "country_name": country_name,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "state_name": state_name,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "start_date": start_date,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "end_date": end_date&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; beforeSend: function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('.message_box').html(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '<img src="tenor.gif" width="40" height="40"/>'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; success: function(data) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var result = $.parseJSON(data);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var string = '<table><thead><th>#</th><th>Lead ID</th><th>Name</th><th>Company</th><th>Location</th><th>Communication</th><th>Last Contact Date</th><th>Next Contact Date</th><th>Lead Status</th><th>Details</th></thead><tbody>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* from result create a string of data and append to the div */&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var i = 1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.each(result, function(key, value) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string += "<tr><td>" + i + "</td><td>" + value['Lead_Id'] + "</td><td>" + value['FirstName'] + ' ' + value['LastName'] + "</td><td>" + value['Company'] + "</td><td>" + value['State'] + '\n' + value['Country'] + "</td><td>" + value['Phone'] + '\n' + value['Email'] + "</td><td>" + value['LastContactDate'] + "</td><td>" + value['NextContactDate'] + "</td><td>" + value['LeadStatus'] + "</td><td><a href='#'>Click Here</a></td></tr>";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = i + 1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string += '</tbody></table>';&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#filterRecords").html(string);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $('.message_box').html('');&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; });});
打开App,查看更多内容
随时随地看视频慕课网APP