开发者

is this $_POST considered empty

I am trying to code a error callback using php and ajax.

What I cannot get past is, I am assinging a variable to a $_POST in PHP to check for an empty value. If empty, then trigger error message.

However, jquery is passing the post to php as carton%5B0%5D:carton%5B1%5D:.

Would php see this as an empty post? What are these numbers etc after carton? carton is actually an array. thanks

+++UPDATE+++

Why is the error triggered when the statement becomes, !empty rather than empty?. This is the code that jquery uses to create an input from a slider change event.

for(var i = 0;i < $(this).val();i++) {
        $("#carton").append('<div data-role="f开发者_C百科ieldcontain"><label for="carton" class="ui-input-text">Enter box ' + (i + 1) + ' number:</label><input type="text" name="carton['+i+']" id="carton['+i+']" class="carton ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" /></div>')
      }


to know whetever $_POST is empty always use var_dump function like this

var_dump($_POST);

And it might be posted as array, am not quite sure but i think arrays in ajax are like this:

array [
[0] => 'item',
[1] => 'item 2'
]

array(2) { [0]=> string(0) "" [1]=> string(0) "" }

array(number) means the number of items in the array, {[0],[1]} means the array items IDs means you can use them like $_POST[1] and $_POST[0], => string(0) ; string is the datatype contained in this array item, (0) is the number of characters in that item.

to check whether the POST data is empty or not, you should use empty() function.

finally, use this to post the content you want via jquery, make sure you modify it with what you need

$.post("test.php", { carton: "this is the content"} );

also you can add more POST fields by adding

, newfield: "this is the new field's content"


If you are sending POST data, then no, $_POST will not be empty.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜