Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php jQuery在使用ajax发布时发布错误文本_Php_Jquery - Fatal编程技术网

Php jQuery在使用ajax发布时发布错误文本

Php jQuery在使用ajax发布时发布错误文本,php,jquery,Php,Jquery,例如,当我通过ajax发帖时,我有时会得到额外的字符。如果文本通过一个php$\u帖子传递,我最终会得到: 这是我的信息jquery127638276487364873268_374632874687326487 99%的时间帖子通过罚款。。。我不确定如何捕获和删除此错误,因为它只在某些时候发生 // this is the ajax that we need to post the footprint to the wall. $('#submitbutton').click(function

例如,当我通过ajax发帖时,我有时会得到额外的字符。如果文本通过一个php$\u帖子传递,我最终会得到:

这是我的信息jquery127638276487364873268_374632874687326487

99%的时间帖子通过罚款。。。我不确定如何捕获和删除此错误,因为它只在某些时候发生

// this is the ajax that we need to post the footprint to the wall.
$('#submitbutton').click(function () {
    var footPrint = $('#footPrint').val();
            var goUserId = '1';
    $.ajax({
       type: 'POST',
       url: '/scripts/ajax-ProfileObjects.php',
       data: 'do=leave_footprint&footPrint=' + footPrint + '&ref=' + goUserId + '&json=1',
       dataType: 'json',
       success: function(data){

            var textError = data.error;
            var textAction = data.action;
            var textList = data.list;

            if (textError == 'post_twice' || textError =='footprint_empty' || textError == 'login_req') {
            // display the error.

            } else {
            // lets fade out the item and update the page.

            }

     });

return false; });

尝试将缓存设置为false。从

缓存布尔值 默认值:数据类型“script”和“jsonp”为true、false
如果设置为false,它将强制浏览器不缓存请求的页面。将cache设置为false也会将查询字符串参数=[TIMESTAMP]附加到URL。

通过一个消除过程,我发现错误是由传递到查询字符串的无效数据引起的

该行:

我注意到如果传递了“??”,footPrint变量总是会破坏脚本。许多成员在提问时会使用“?”when而不是单个“?”

通过将footPrint变量包装在encodeURIComponent中,我可以将所有文本发送到PHP脚本,而无需中断URL字符串

新行:


这个解决方案对我有效。。。问题、评论和建议仍然欢迎。

您需要发布代码或示例以获得答案。谢谢,我已更新了代码,并将查看是否显示任何帖子。如果是缓存问题,我是否也应该设置PHP文件no not cache?@Philip我想你不需要设置任何PHP头文件_=[时间戳]参数用于此目的
data: 'do=leave_footprint&footPrint=' + footPrint + '&ref=' + goUserId + '&json=1',
 data: 'do=leave_footprint&footPrint=' + encodeURIComponent(footPrint) + '&ref=' + goUserId + '&json=1',