0

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);
        },

    });
2
  • 1
    use "decodeURIComponent()" Commented Jun 2, 2015 at 5:18
  • what you have try for decode url in php?? Commented Jun 2, 2015 at 5:21

5 Answers 5

1

Use string urldecode( string $str ) function to decode your encoded URL data for more follow this link

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

Comments

0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.