通过AJAX发送HTML服务器端PHP [英] Send HTML to server-side PHP through AJAX

查看:101
本文介绍了通过AJAX发送HTML服务器端PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送HTML是一个形式到服务器端脚本,所以我可以将它保存在数据库中。我要送一个查询字符串,每次在HTML中包含像一个逗号或符号字符,在HTML的其余部分被截断在这一点上。

I'm trying to send HTML that is in a form to a server-side script so I can save it in the database. What I'm sending is a query string, and every time the HTML contains a character like a comma or ampersand, the rest of the HTML gets truncated at that point.

在此先感谢!

推荐答案

发送请求时,你应该适当的URL连接code parameteres:

When sending a request you should properly URL encode parameteres:

$.ajax({
    url: 'foo.php',
    data: { html: '<html>You can use whatever characters you want here</html>' },
    type: 'GET',
    success: function(result) {

    }
});

$.ajax({
    url: 'foo.php',
    data: { html: $('#someTextFieldWhichMightContainHtml').val() },
    type: 'GET',
    success: function(result) {

    }
});

现在你可以放心地阅读 HTML 变量在你的PHP脚本: $ GET [HTML]

Now you can safely read the html variable in your PHP script: $.GET["html"].

我想,现在的code看起来是这样的:

I suppose that right now your code looks something like this:

$.ajax({
    url: 'foo.php?html=' + $('#someTextField').val(),
    type: 'GET',
    success: function(result) {

    }
});

我会建议您不要使用字符串连接,并始终使用数据散。

这篇关于通过AJAX发送HTML服务器端PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆