简体   繁体   中英

how to decode serialize url from javascript in php

please consider following snippet i have submited a form which contains a background image url , i have serialize the form data . in php the URL is not decoding , how to get orignal url

$("#slider_settings_form").submit(function(e) {
    var postData = $(this).serialize();
    submited form
    $.ajax({
        url: ajaxurl,
        data: {
            "params": postData,
            "action": "saveFormSettings"
        },
        method: "POST",
        success: function(response) {
            alert(response);
        },

    });

使用string urldecode( string $str )函数解码您编码的 URL 数据以获取更多信息,请点击此链接

A successful parsing could be done by adding urldecode like this:

parse_str(urldecode($_REQUEST['params']), $params);

urldecode is important because it converts url encoded string into parsable string.

If you want to achieve it from javascript you can use these methods:

var uri = "http://stackoverflow.com/questions/30587877/how-to-decode-serialize-url-from-javascipt-in-php"
var uri_enc = encodeURIComponent(uri); //for encoding
var uri_dec = decodeURIComponent(uri_enc); //for decoding

Here is the link for more details: Url decode and encode

Have a look at this related question .

We need to see how you're decoding the data in PHP to help you, but in addition to the answer ahead of mine (suggesting the use of urldecode ), you should also make sure postData actually has data in it.

Only "successful controls" are serialized to the string [...] - second answer

It's entirely possible postData is nil. You should test it by alerting it and go from there. The question I linked to has a more thorough answer with code examples.

var postData = $(this).serialize(); -- this would create a query string like 'a=1&b=2' , where a and b are form fields. You might want to fetch the value of a or b -- the following code will help you:

parse_str($_GET['params'], $params);
// then you can use $params['a'] to fetch form field 'a'
print_r($params);
// => 
//Array
//(
//    [a] => 1
//    [b] => 2
//)

For more about parse_str , see http://php.net/manual/en/function.parse-str.php

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