简体   繁体   中英

URL breaks into array when submit in Symfony3

When I am submitting URL in Symfony3 using AJAX it breaks into array

URL

HTML and AJAX code:

<input type="text" name="url" id="url" class="form-control"  placeholder="Search url" >
<script>
                $('#search_submit').click(function(){     
                    var feed_url = $("#url").val();  
                    $.ajax({
                        type: "POST",
                        url: "/getdata",
                        data:  "feed_url="+feed_url,
                        dataType: "json",
                        success: function(msg)
                        {
                            if(msg.status == 1){
                                alert("display")
                            }
                            else{
                                alert("No Product found");
                            }                           
                        },
                        beforeSend: function()
                        {
                            $("#loading-sp").show();
                        }
                    });

                  return false ;
                });
</script>

Controller:

    /**                                                                                   
    * @Route("/getdata")
    */
    public function getfeedAction(Request $request)    
    {       
       print_r($request->request->get('feed_url'));exit;
    }

It just displays this and not the full URL. However, if I print $_POST it shows:

Array
(
    [feed_url] => pf.tradetracker.net/?aid=1
    [type] => xml
    [encoding] => utf-8
    [fid] => 251713
    [categoryType] => 2
    [additionalType] => 2
    [limit] => 20
)

Thanks In advance.

我通过在javascript中添加encodeURIComponent修复了此问题

data:  "feed_url="+encodeURIComponent(feed_url)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM